LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 01-14-2012, 01:27 AM   #1
abhishekgit
Member
 
Registered: Jan 2012
Location: India
Distribution: Ubuntu, Gentoo, Fedora, Rhel5,openSUSE
Posts: 165

Rep: Reputation: 12
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...
 
Old 01-14-2012, 01:31 AM   #2
nonamedotc
Member
 
Registered: Mar 2011
Location: /
Distribution: Fedora (typically latest release or development release)
Posts: 370

Rep: Reputation: Disabled
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.
 
1 members found this post helpful.
Old 01-14-2012, 01:33 AM   #3
fukawi1
Member
 
Registered: Apr 2009
Location: Melbourne
Distribution: Fedora & CentOS
Posts: 854

Rep: Reputation: 190Reputation: 190
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.
 
1 members found this post helpful.
Old 01-14-2012, 01:34 AM   #4
Telengard
Member
 
Registered: Apr 2007
Location: USA
Distribution: Kubuntu 8.04
Posts: 579
Blog Entries: 8

Rep: Reputation: 147Reputation: 147
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
 
Old 01-14-2012, 01:35 AM   #5
btmiller
Senior Member
 
Registered: May 2004
Location: In the DC 'burbs
Distribution: Arch, Scientific Linux, Debian, Ubuntu
Posts: 4,275

Rep: Reputation: 370Reputation: 370Reputation: 370Reputation: 370
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.
 
1 members found this post helpful.
Old 01-14-2012, 01:48 AM   #6
nonamedotc
Member
 
Registered: Mar 2011
Location: /
Distribution: Fedora (typically latest release or development release)
Posts: 370

Rep: Reputation: Disabled
Quote:
Originally Posted by btmiller View Post
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.
 
1 members found this post helpful.
Old 01-14-2012, 02:02 AM   #7
abhishekgit
Member
 
Registered: Jan 2012
Location: India
Distribution: Ubuntu, Gentoo, Fedora, Rhel5,openSUSE
Posts: 165

Original Poster
Rep: Reputation: 12
Thanks!!

Thank you all.!
$ bash hello.sh worked perfectly. That was my first script.:-)
 
Old 01-14-2012, 11:34 AM   #8
mrrangerman
Member
 
Registered: Oct 2007
Location: MI
Distribution: Debian Slackware
Posts: 528

Rep: Reputation: 50
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.
 
Old 01-14-2012, 11:50 AM   #9
alan_ri
Senior Member
 
Registered: Dec 2007
Location: Croatia
Distribution: Debian GNU/Linux
Posts: 1,733
Blog Entries: 5

Rep: Reputation: 127Reputation: 127
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/
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
LXer: Terminal functions for shell scripting with Shell Curses LXer Syndicated Linux News 0 03-27-2008 12:50 AM
SHELL scripting/ shell functions mayaabboud Linux - Newbie 6 12-26-2007 09:18 AM
Shell Scripting: Getting a pid and killing it via a shell script topcat Programming 15 10-28-2007 03:14 AM
teaching shell scripting: cool scripting examples? fax8 Linux - General 1 04-20-2006 05:29 AM
shell interface vs shell scripting? I'm confused jcchenz Linux - Software 1 10-26-2005 04:32 PM


All times are GMT -5. The time now is 11:11 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration