different between test.sh and test.ksh
1. I don't get it why sometime I saw files with extension .sh and .ksh. I do know sh = bourne shell and .ksh is korn shell. I just don't understand the purpose of when to use it.
2. even with the file .sh, within the file, they still start out with !#ksh why? |
In Linux extensions generally have no purpose like they do in DOS/Windows so aren't required. If someone puts an extension on a file they're just trying to let people know what it is without having to open it or run the "file <file>" command on it.
Many folks put .sh on ALL shell scripts (Bourne, BASH, Korn, Posix sh) and .pl on all Perl scripts. It is not required and neither helps nor hurts the way the script runs. It is more of a convention than anything else. If the contents/ownership/permissions of the following are all the same they would do the same thing: script.sh script.ksh script.bash script.pl script.billybob script yomama mymama this_aint_a_script Notice in above that I say even if it has a .pl it will run even if the interpreter inside it bash. Since the .pl is just part of the name it doesn't really mean "this is perl". Even naming it "this_aint_a_script" won't keep it from running if in fact it IS a script. One caveat: They'll all do the same thing so long as there is nothing inside the script that is dependent on the name it was run as. It is actually possible to make one script (or binary) and put code inside it that looks at the name it was called as to determine how to run. That is more commonly seen in binaries than scripts though but I mention it just to avoid the inevitable pedantic response by someone else. |
Quote:
Code:
#!/bin/bash |
Quote:
Also the interpreter line itself is not even required. If you run a script in your current shell and it is designed to work in your current shell it will run just fine. However, it is always best to put the interpreter just to insure it runs in the shell you intended it for. Not having the interpreter could be a problem if you were say running in csh then tried to run either a perl or a bash script - csh wouldn't understand the commands it was seeing. The interpreter line tells it to invoke the appropriate shell as to run the commands. |
Quote:
|
All times are GMT -5. The time now is 10:21 AM. |