The first line, #!/bin/bash
, tells Linux where to find the interpreter. The script should also be executable with chmod +x script.sh
, which it appears you did.
It is highly likely that you created this file with a windows editor, which will place a <cr><lf>
at the end of each line. This is the standard under dos / windows. OS X will place a <cr>
at the end of each line. However, under Unix / Linux, the standard is to just put a <lf>
at the end of the line.
Linux is now looking for a file called /bin/bash<cr>
to interpret the file, where <cr>
is a carriage return character, which is a valid file character under Linux. Such a file doesn’t exist. Hence the error.
Solution: Edit the file with an editor on Linux and get rid of the extra <cr>
. One tool that usually works when the file is edited on Windows is dos2unix
.
Related Posts:
- Why do you need to put #!/bin/bash at the beginning of a script file?
- How does “cat << EOF" work in bash?
- How to count lines in a document?
- What does `set -x` do?
- How do I know the script file name in a Bash script?
- What is “-bash: !”: event not found”
- How can I fully log all bash scripts actions?
- How do I deal with a filename that starts with the hyphen (-) character?
- Bash: No such file or directory?
- “Couldn’t find a file descriptor referring to the console” on Ubuntu bash on Windows
- gzip: stdin: not in gzip format tar: Child returned status 1 tar: Error is not recoverable: exiting now
- Pass a password to ssh in pure bash
- -bash: syntax error near unexpected token `newline’ for display command
- How do I use grep to search the current directory for all files having the a string “hello” yet display only .h and .cc files?
- “sed” command in bash
- Explaining the ‘find -mtime’ command
- Pseudo-terminal will not be allocated because stdin is not a terminal
- Extract file basename without path and extension in bash
- Given two directory trees, how can I find out which files differ by content?
- mv: cannot stat error : No such file or directory error
- Pseudo-terminal will not be allocated because stdin is not a terminal
- ./configure : /bin/sh^M : bad interpreter
- Trying to use bash on Windows and got no installed distributions message
- What is the difference between “#!/usr/bin/env bash” and “#!/usr/bin/bash”?
- -bash: fork: Cannot allocate memory
- Is there a “goto” statement in bash?
- How to get the process ID to kill a nohup process?
- Writing a simple shell in C using fork/execvp
- chmod: changing permissions of ‘my_script.sh’: Operation not permitted
- tar: add all files and directories in current directory INCLUDING .svn and so on
- What does set -e mean in a bash script?
- What does set -e mean in a bash script?
- “find: paths must precede expression:” How do I specify a recursive search that also finds files in the current directory?
- Bash script prints “Command Not Found” on empty lines
- Pipe to/from the clipboard in a Bash script
- Linux Bash: Move multiple different files into same directory
- How do I write stderr to a file while using “tee” with a pipe?
- How to include file in a bash shell script
- How to enable Bash in Windows 10 developer preview?
- What does ‘bash -c’ do?
- bash sh – command not found
- How can I sort du -h output by size
- What are the functional differences between .profile .bash_profile and .bashrc
- How to run a command multiple times, using bash shell?
- How do I prevent accidental rm -rf /*?
- How do I sleep for a millisecond in bash or ksh
- What’s the best way to check if a volume is mounted in a Bash script?
- Keeping a linux process running after I logout
- What useful things can one add to one’s .bashrc? [closed]
- How to add a timestamp to bash script log?
- Colors in bash after piping through less?
- Linux command line best practices and tips?
- How to run command as user who has /usr/sbin/nologin as Shell?
- How to get pid of just started process
- Can you have more than one ~/.ssh/config file?
- SSH from A through B to C, using private key on B [closed]
- How to apply a filter to real time output of `tail -f `?
- How to remove invalid characters from filenames?
- zcat/gzcat works in linux, not on osx. general linux/osx compatibility
- Amazon Linux: apt-get: command not found
- How do I find all files containing specific text on Linux?
- Where can I find php.ini?
- Linux: ‘Username’ is not in the sudoers file. This incident will be reported
- “E: Unable to locate package python-pip” on Ubuntu 18.04 [duplicate]
- How do I split a string on a delimiter in Bash?
- Linux error while loading shared libraries: cannot open shared object file: No such file or directory
- TCP congestion control version: HTCP module vs highspeed module in linux kernel
- How to use regex with find command?
- Compile the Fortran program in Windows using gfortran
- How can I set the ‘backend’ in matplotlib in Python?
- Yum fails with – There are no enabled repos.
- Unable to establish SSL connection upon wget on Ubuntu 14.04 LTS
- configure: error: cannot run C compiled programs
- Difference between exec, execvp, execl, execv?
- Restarting cron after changing crontab file?
- WordPress cloning issue
- Can scp copy directories recursively?
- What is the difference between double and single square brackets in bash?
- Why does my hostname appear with the address 127.0.1.1 rather than 127.0.0.1 in /etc/hosts?
- Linux command to inspect TXT records of a domain [closed]
- What does a + mean at the end of the permissions from ls -l?
- What version of RHEL am I using?
- How do you make it obvious you are on a production system?
- How can I verify if TLS 1.2 is supported on a remote web server from the RHEL/CentOS shell?
- Mount CIFS Host is down
- List of files installed from apt package
- How to copy a large number of files quickly between two servers
- Allow SFTP but disallow SSH?
- How can I export the privileges from MySQL and then import to a new server?
- Is there a directory equivalent of /dev/null in Linux?
- Can I send some text to the STDIN of an active process running in a screen session?
- How can I get processor/RAM/disk specs from the Linux command Line? [duplicate]
- Is there a way to see the execution tree of systemd?
- How to determine the hostname from an IP address in a Windows network?
- create home directories after create users
- How do I redirect subdomains to a different port on the same server?
- Running Cron every 2 hours [duplicate]
- How to check the physical status of an ethernet port in Linux?
- What does “debconf: delaying package configuration, since apt-utils is not installed” mean?
- In Linux, what is the difference between “buffers” and “cache” reported by the free command?