Question:
How do I open a script in UNIX?
Joe Schmoe
2013-01-08 19:00:41 UTC
UNIX is not my forte, but the old IT guy has a script to run, modify and email a file to a particular email address. The email address and I need to alter it. The path is ./home/mike/rungnt.sh Any help would be great.
Four answers:
husoski
2013-01-08 19:27:54 UTC
Are you sure there's a dot at the front of that path? home is normally a root directory, and the ./ part will only find the script if you set the working directory to the root (/). Without the ., /home/mike/rungnt.sh should work from anywhere.



The script has to be marked exectuable. If you've just downloaded it as a text file, that might not be the case. You may have to run "chmod +x /test/mike/rungnt.sh" to enable execution.



To edit, pick an editor that's installed and you know. vi and emacs are the classics, but hard to pick up if you haven't used them before. ged and joe are newer and easier, but not everyone has them. If you have a GUI environment, see what's in the menus that you recognize and can figure out.



Good luck!
Robert
2013-01-09 03:13:37 UTC
You use text editors and if they have an option to save with UNIX encoding you pick that option. Think even Notepad will do if on Windows (or TextPad and/or UltraEdit) and emacs or vi will do on Unix/Linux, TextWrangler on Mac, on that criteria (but during the first exchanges of files you should never clobber the already existing script ... version control or "making sure it works independently first" is needed).



The permissions on the file need to remain the same if you already have a working scenario. A unix script can run just by going



[unix-script-name]



on the command line if they have the execute permission allowed (see the source link regarding chmod).



If the script deliberately does not have this execute permission, for a reason, the script can be run via ...



/bin/sh [unix-script-name]

OR

sh [unix-script-name]



To find out the existing permissions for your unix script, go:



ls -la [unix-script-name]



To type the script to the screen:



cat [unix-script-name]



To edit the script (you need to know vi ... especially to save and exit is :!wq):



vi [unix-script-name]
potatocouch
2013-01-10 02:06:42 UTC
backup the existing script in case you mess it up

cp /home/mike/rungnt.sh /home/mike/backup_rungnt.sh



# find where to edit the email address and the line number

grep -n the_email_address /home/mike/rungnt.sh

123: root@rungnt.org



# edit the file with nano exactly at that specific line

nano +123 rungnt.sh



# if you don't mind searching

nano rungnt.sh



the way you are executing the script is fine as long its execute bit is enabled.

1) ./path/to/script

2) /path/to/script if the path is in your .bashrc file

3) /bin/sh /path/to/script
Lisa A
2013-01-09 03:36:55 UTC
The OS will run the script with the correct shell. It should have #! /bin/sh or some such as the first line. That's what the OS uses to understand what to do.


This content was originally posted on Y! Answers, a Q&A website that shut down in 2021.
Loading...