Originally Posted by
dagamegamer
How do you run commands from a .sh file. I've been looking on for how to make on but the only one i found was how to print text on the screen.
TLDP is full of useful guides.
The
Linux
Documentation
Project
https://tldp.org/
https://www.tldp.org/LDP/Bash-Beginn...ers-Guide.html
BTW, Unix systems don't care about file extensions. .sh doesn't mean anything special to the system. It is slightly handy for humans, but humans lie. I've created a few .sh files, but they quickly outgrew the complexity I was willing to implement using Bourne Shell (that where "sh" originated), so I re-implemented them in a much more powerful scripting language, perl5. I could have changed the name to .pl, but I'm lazy and left it as .sh. No matter, it works just fine provided 3 things are true.
- File is readable by the userid trying to run the script
- File has eXecute permissions for the user running the script
- the 1st line correctly says, in the correct way, which interpreter to be used by the script
chmod +r path-to-file
chmod +x path-to-file
1st line has interpreter, specified, for example:
The #! is critical - # is a comment. #! says, use this interpreter. It must be on the 1st line, not the 2nd, 5th, 900th line, the 1st line of the script. Every line after that must be compatible with whatever interpreter is specified.
More interpreter examples:
Code:
/home/tf/.rvm/rubies/ruby-1.9.3-p194/bin/ruby
There are many more perfectly acceptable scripting languages. Use whatever you like.
If you want examples of full programs in 500+ languages, check out http://rosettacode.org/wiki/Main_Page . Both scripted and compiled language examples are there. Some of the script examples are missing that 1st line, but that's it. They are full implementations.
Bookmarks