🐧
Linux
  • Introduction
  • 🖇️general
    • essentials
    • other commands
    • Superuser-do (sudo)
    • SUID, SGID, sticky bit
    • /dev/null
    • environment variables
    • special variables
    • shebang
  • spool
  • 🔧bash
    • overview
    • redirection
    • loop
    • .bashrc
  • text processing
    • grep
    • sed
    • awk
  • xxd/hexdump
  • text editors
    • nano
    • vi/vim
  • 📂filesystem & directories
    • Filesystem Hierachy Standard (FHS)
      • /etc
        • hosts, hosts.allow, hosts.deny
        • /cron.d
        • /httpd
        • /samba.d
        • hostname
        • crontab
        • shadow
        • passwd
        • profile
        • services
      • /dev
      • /proc
        • version
      • /mnt
      • /opt
      • /sbin
      • /lib
      • /usr
      • /tmp
      • /var
      • /bin
      • /run
    • chroot
  • find
  • locate
  • ⌚processes & jobs
    • cronjob
    • daemon
  • ⛓️system
    • systemctl
    • hostname
    • systemd
  • 🗃️media
    • ffmpeg
    • pdftk
  • 🔒Security
    • ufw
  • firejail
  • apparmor
  • 📦Package management
    • dpkg
    • apt/apt-get
  • Storage
    • lsblk
    • mount/umount
  • df/du
  • user management
    • chsh
  • Networking
    • Introduction
    • routing table/interface management
    • /etc/hosts, /etc/hosts.allow, /etc/hosts.deny
Powered by GitBook
On this page
  1. general

shebang

shebang is the character sequence #! used at the start of a script to indicate the values that follows will be an interpreter directive. This essentially controls which interpreter parses and interprets the instructions in the particular computer program that follows.

Example

Given the following file named test

  1. The contents of the test file is shown to contain a print statement in Python language

  2. The file executed with the ./test command

    • An error is thrown

    • This is because the shebang is not specified. Thus, the default interpreter value (/bin/sh) is used.

  3. To specify to the shell to use the python interpreter (/usr/bin/python3), the shebang needs to be included at the top of the script

  4. When the script is ran again, the interpreter /usr/bin/python3 is used.

# 1)
$ cat test
print("hello friend")

# 2)
$ ./test
./test: line 2: syntax error near unexpected token `"hello friend"'
./test: line 2: `print("hello friend")'

# 3)
$ which python3
/usr/bin/python3

$ nano test
...

$ cat test
#!/usr/bin/python3 
print("hello world")

# 4)
$ ./test
hello friend
Previousspecial variablesNextspool

Last updated 5 months ago

🖇️