Make sure your first line is:
#!/bin/bash
Enter your path to bash if it is not /bin/bash
Try running:
dos2unix script.sh
That wil convert line endings, etc from Windows to unix format. i.e. it strips \r (CR) from line endings to change them from \r\n (CR+LF)
to \n (LF)
.
More details about the dos2unix
command (man page)
Another way to tell if your file is in dos/Win format:
cat scriptname.sh | sed 's/\r/<CR>/'
The output will look something like this:
#!/bin/sh<CR> <CR> echo Hello World<CR> <CR>
This will output the entire file text with <CR>
displayed for each \r
character in the file.
Related Posts:
- How do I deal with a filename that starts with the hyphen (-) character?
- Bash: No such file or directory?
- Why do you need to put #!/bin/bash at the beginning of a script file?
- “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
- How does “cat << EOF" work in bash?
- Pseudo-terminal will not be allocated because stdin is not a terminal
- What is difference between arm64 and armhf?
- 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
- Uncompress tar.gz file
- Pseudo-terminal will not be allocated because stdin is not a terminal
- screen Cannot open your terminal ‘/dev/pts/0’ – please check
- ./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?
- Bash script: bad interpreter
- How to count lines in a document?
- What does `set -x` do?
- 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?
- 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
- python-dev installation error: ImportError: No module named apt_pkg
- How to enable Bash in Windows 10 developer preview?
- What does ‘bash -c’ do?
- bash sh – command not found
- How do I know the script file name in a Bash script?
- How can I sort du -h output by size
- Anyone else experiencing high rates of Linux server crashes during a leap second day?
- What are the functional differences between .profile .bash_profile and .bashrc
- How can I run Debian stable but install some packages from testing?
- What’s the best way of handling permissions for Apache 2’s user www-data in /var/www?
- 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 is “-bash: !”: event not found”
- 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?
- List of files installed from apt package
- 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
- How to install/change locale on Debian?
- Can you have more than one ~/.ssh/config file?
- How can I export the privileges from MySQL and then import to a new server?
- SSH from A through B to C, using private key on B [closed]
- Is it possible to reboot a Linux OS without rebooting the hardware?
- How can I fully log all bash scripts actions?
- How to apply a filter to real time output of `tail -f `?
- What does “debconf: delaying package configuration, since apt-utils is not installed” mean?
- What should I do when I got the KEYEXPIRED error message after an apt-get update?
- How to remove invalid characters from filenames?
- zcat/gzcat works in linux, not on osx. general linux/osx compatibility
- What is the debian-sys-maint MySQL user (and more)?
- How should an IT department choose a standard Linux distribution?
- Chmod 777 to a folder and all contents [duplicate]
- Cannot connect to the Docker daemon at unix:/var/run/docker.sock. Is the docker daemon running?
- Confused about stdin, stdout and stderr?
- What’s a .sh file?
- Amazon Linux: apt-get: command not found
- How to set the environmental variable LD_LIBRARY_PATH in linux
- What’s a .sh file?
- How to create a file in Linux from terminal window? [closed]
- How can I symlink a file in Linux? [closed]
- How to fix ‘sudo: no tty present and no askpass program specified’ error?
- Kill detached screen session [closed]
- How do I grep recursively?
- How do I grep recursively?
- How to get the url of the current svn repo?
- What does pss mean in /proc/pid/smaps
- apt-get error: Sub-process /usr/bin/dpkg returned an error code (1)
- How do I find all files containing specific text on Linux?
- How to unmount a busy device
- How to unmount a busy device
- error: ‘Can’t connect to local MySQL server through socket ‘/var/run/mysqld/mysqld.sock’ (2)’ — Missing /var/run/mysqld/mysqld.sock
- performing HTTP requests with cURL (using PROXY)
- Where can I find php.ini?
- error: ‘Can’t connect to local MySQL server through socket ‘/var/run/mysqld/mysqld.sock’ (2)’ — Missing /var/run/mysqld/mysqld.sock
- No space left on device
- How do I grep recursively?
- How can I recursively find all files in current and subfolders based on wildcard matching?