How to run shell script *.sh?

If you are new to Linux or new to Sabayon Linux and just not sure where to post, here ya go. Post without fear of being told to RTFM :-)

Moderator: Moderators

How to run shell script *.sh?

Postby bg3075 » Tue Nov 17, 2009 4:08

Sorry again, I am a newbie with SL, but with Fedora ran shell scripts (.sh) via terminal:
Code: Select all
sh <scriptname>.sh
I cannot figure out the equivalent command in SL. See attempt below, taken from ... ject-intro.
Code: Select all
[email protected] ~/Downloads/clonezilla-sysresccd/create-clonezilla-sysresccd-2.6.0 $ create-clonezilla-sysresccd -p 2
-bash: create-clonezilla-sysresccd: command not found
Code: Select all
[email protected] ~/Downloads/clonezilla-sysresccd/create-clonezilla-sysresccd-2.6.0 $ sh create-clonezilla-sysresccd -p 2
did nothing that I could see, but only went back to command-line prompt. I know the shell script exist in the directory (above) from which I issued the command. Can anyone let me know what I may be doing wrong?
sabayon 4.2 / Windows XP MCE
Intel 2.4 Ghz
nvidia GeForce 8600
Baby Hen
Posts: 12
Joined: Wed Nov 11, 2009 5:48

Re: How to run shell script *.sh?

Postby Fitzcarraldo » Tue Nov 17, 2009 7:33

Code: Select all
[email protected] ~ $ ls -la
-rw-r--r-- 1 bill users 33 2009-11-17 06:29
[email protected] ~ $ cat
echo "Hello world!"

[email protected] ~ $ sh
Hello world!
[email protected] ~ $

If you're trying to run it as another user, then try making the shell script executable:
Code: Select all
[email protected] ~ $ chmod 777
[email protected] ~ $ ls -la
-rwxrwxrwx 1 fitzcarraldo users 33 2009-11-17 06:29
[email protected] ~ $
User avatar
Sagely Hen
Posts: 8084
Joined: Sat Mar 10, 2007 5:40
Location: United Kingdom

Re: How to run shell script *.sh?

Postby thecata » Tue Nov 17, 2009 16:05

You may need to check that the file you are trying to run is an executable. In order to set the executable flag for that file (for all users), you can run:
Code: Select all
chmod +rx your_file_goes_here

This command will set read and execute rights for everybody (owner, group and others).
In your case, it seems like "create-clonezilla-sysresccd" is the script you are trying to run. Also, check the first line in the file, and see if it is something like "#!/bin/sh". In that case, you need to make sure that you have that interpreter (the file following "#!" (in this case sh, in Fitzcarraldo's, bash).
Also, running an executable from the current folder is done with "./your_script", because by default, the PATH variable does not contain the current folder (you may change it by editing a line in "~/.bashrc" : add ":." at the end of the PATH variable declaration if there is one, or just add the line "export PATH=${PATH}:." at the end of the "~/.bashrc" file - the second method works just fine even if the PATH variable is set somewhere else in the file). After changing the PATH variable, you will need to close and reopen the terminal, or relogin. To check that the changes took effect, type "echo $PATH" and see if the "." is listed in the output (should be in the end if you followed the above method).

PS: To clarify even further the "what I may be doing wrong" part of your post, that is caused because when you run a command, the system will try to use folders listed in the PATH variable to search for the executable. Since neither the actual folder is found (in your case, "/home/barry/Downloads/clonezila-sysresccd/create-clonezilla-sysresccd-2.6.0"), nor the current folder (".") is in the PATH variable, the system cannot find the actual executable (hence, the "command not found" error).
As for the second part, when you tried to run clonezilla with sh in front, it should have worked... since I've never used it myself, I'm guessing you need to recheck the parameters you are passing to it by checking the clonezilla documentation (website, man pages or whatever is provided).
It is also possible that the program actually completed successfully. From what I've picked up in a hurry from the link you provided, clonezilla uses some files where profiles are stored; you should read them carefully and modify them if necessary - they specify where the cd images are generated (maybe everything works as it should, but you just missed the resulting files).
Catalin Pol
Location: Romania
Linux user since 2004; Sabayon user since 2006
Simple Hen
Posts: 77
Joined: Sun Nov 12, 2006 11:40
Location: Romania, Cluj

Return to Beginners|Newbies Area

Who is online

Users browsing this forum: No registered users and 3 guests