LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   Shell scripting. (https://www.linuxquestions.org/questions/linux-newbie-8/shell-scripting-923702/)

abhishekgit 01-14-2012 12:27 AM

Shell scripting.
 
Hello everyone,
I am completely new to linux and i know few terminal commands and i have fedora 13 installed. I am working on shell scripting. I am writing the script in vim-X11. Am i doing the rite thing??. And I've no idea how exactly to run that script after saving it. Kindly Help.


Regards...

Janus_Hyperion 01-14-2012 12:31 AM

This might be useful for you.
Shell Scripting tutorial

As for using vim-x11, some prefer vi/vim and others emacs. It is a matter of preference. Just use what you are comfortable with.

fukawi1 01-14-2012 12:33 AM

you will need to set the script's execute permission
Code:

chmod u+x script.sh
and then you can run it by
Code:

./script.sh
You can also run it by using
Code:

bash script.sh
Assuming you are running bash, if not you would change this to the appropriate shell.

Telengard 01-14-2012 12:34 AM

Any plain text editor is fine for shell scripting. After you save the script just set the executable bit and call it directly from the terminal.

Code:

$ chmod 'u+x' your-script
$ ./your-script

HTH

btmiller 01-14-2012 12:35 AM

Sounds fine to me :-). You might try running vim just in the terminal so you can get used to non-graphical applications. You might also want to look at some of the bash guides at www.tldp.org to get some basic ideas about shell scripting.

You save your script as a text file, and you can run it by:

Code:

bash filename.sh
assuming filename.sh is the name of the file with your script. However, there's an easier way too. You can add what's called a shebang to the top of your script, e.g.:

Code:

#!/bin/bash
Then, if you make your file executable, you can just run it (and it will invoke bash automatically, e.g.:

Code:

$ vi filename.sh # create the script
$ chmod +x filename.sh # make it executable!
$ ./filename.sh # run it

BTW, the dollar signs in the above are supposed to represent the shell prompt; you don't type them in. Good luck and happy scripting!

BTW, you might consider upgrading your Fedora at some point. I believe that 13 is a bit out of date.

Janus_Hyperion 01-14-2012 12:48 AM

Quote:

Originally Posted by btmiller (Post 4574169)
However, there's an easier way too. You can add what's called a shebang to the top of your script,

I don't remember reading this term before. Thanks.

abhishekgit 01-14-2012 01:02 AM

Thanks!!
 
Thank you all.!
$ bash hello.sh worked perfectly. That was my first script.:-)

mrrangerman 01-14-2012 10:34 AM

If you just want to test your script without making it executable just give the command

Code:

source script name
do this command from within the directory the script is located.

alan_ri 01-14-2012 10:50 AM

Open Terminal or Konsole or whatever, it depends on what distro and what DE you're using, run the command;
Code:

man bash
Manual pages are lovely, they go by;
Code:

man whatever
Have a look here too; http://ss64.com/bash/

That's for start.

Then check these 2 links, in that order (second one is something btmiller suggested);
http://linuxconfig.org/Bash_scripting_Tutorial
http://tldp.org/LDP/abs/html/


All times are GMT -5. The time now is 06:46 PM.