Bash Commands - chmod # Invoking script

1. Invoke

Having written the script, you can invoke it by bash scriptname

Much more convenient is to make the script itself directly executable with a chmod.

Either:

$ chmod 555 scriptname            (gives everyone read/execute permission)  or

$ chmod +rx scriptname             (gives everyone read/execute permission)


$ chmod u+rx scriptname            (gives only the script owner read/execute permission)

2. Test

Having made the script executable, you may now test it by

./scriptname


For example:

$ cat >test_chmod << "EOF"                # Create a (script) file named test_chmod.

> #!/bin/bash                                              # the "sha-bang" line. Indicate calling command interpreter.

> echo "Hello,bash world!"                    # Write a script command.

> EOF                                                           # End the file.

$ chmod 555 test_chmod                      # Invoke the script file, gives everyone read/execute permission.

$ ./test_chmod                                          # test it!

Hello,bash world!                                      # The script file was run.

3. "sha-bang" line

#!/bin/sh
#!/bin/bash
#!/usr/bin/perl
#!/usr/bin/tcl
#!/bin/sed -f
#!/bin/awk -f

Each of the above script header lines calls a different command interpreter, be it /bin/sh, the default shell
(bash in a Linux system) or otherwise.

Note: $chmod 4755 filename                   # Give filename root permission.

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章