It’s a convention so the *nix shell knows what kind of interpreter to run.
For example, older flavors of ATT defaulted to sh (the Bourne shell), while older versions of BSD defaulted to csh (the C shell).
Even today (where most systems run bash, the “Bourne Again Shell”), scripts can be in bash, python, perl, ruby, PHP, etc, etc. For example, you might see #!/bin/perl
or #!/bin/perl5
.
PS: The exclamation mark (!
) is affectionately called “bang”. The shell comment symbol (#
) is sometimes called “hash”.
PPS: Remember – under *nix, associating a suffix with a file type is merely a convention, not a “rule”. An executable can be a binary program, any one of a million script types and other things as well. Hence the need for #!/bin/bash
.
Related Posts:
- How does “cat << EOF" work in bash?
- What is the difference between “#!/usr/bin/env bash” and “#!/usr/bin/bash”?
- Bash script: bad interpreter
- 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
- -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
- How do I split a string on a delimiter in Bash?
- What’s a .sh file?
- How to fix ‘sudo: no tty present and no askpass program specified’ error?
- What is the preferred Bash shebang?
- error: ‘Can’t connect to local MySQL server through socket ‘/var/run/mysqld/mysqld.sock’ (2)’ — Missing /var/run/mysqld/mysqld.sock
- how to find libstdc++.so.6: that contain GLIBCXX_3.4.19 for RHEL 6?
- subprocess.Popen(): OSError: [Errno 8] Exec format error in python?
- How can I recursively find all files in current and subfolders based on wildcard matching?
- Curl command for https ( SSL )
- Bash scripting missing ‘]’
- WSL – GEDIT Unable to init server: Could not connect: Connection refused
- Uncompress tar.gz file
- curl: (6) Could not resolve host: google.com; Name or service not known
- How to pass password to scp?
- scp gives “not a regular file”
- CentOS error – sudo: effective uid is not 0, is sudo installed setuid root?
- Merge / convert multiple PDF files into one PDF
- scp from Linux to Windows
- How do I find the MySQL my.cnf location
- node.js: cannot find module ‘request’
- What is the reason and how to avoid the [FIN, ACK] , [RST] and [RST, ACK]
- wget returns “Unable to establish SSL connection”
- error : storage class specified for parameter
- WordPress Update – This is usually due to inconsistent file permissions.: wp-admin/includes/update-core.php
- Anyone else experiencing high rates of Linux server crashes during a leap second day?
- Can I nohup/screen an already-started process?
- In my /etc/hosts/ file on Linux/OSX, how do I do a wildcard subdomain?
- Shell command to monitor changes in a file
- Difference in sites-available vs sites-enabled vs conf.d directories (Nginx)?
- Disk full, du tells different. How to further investigate?
- Filename length limits on linux?
- best way to clear all iptables rules
- How can I rename a Unix user?
- How to re-order windows, change the scroll shortcut, and modify the status bar contents in GNU Screen?
- How to prevent a user from login in, but allow “su – user” in Linux?
- I have a keypair. How do I determine the key length?
- Why drop caches in Linux?
- swap partition vs file for performance?
- Best way to disable swap in Linux
- How can I zip/compress a symlink?
- How to find the physical volume(s) that hold a logical volume in LVM