LinuxQuestions.org
View the Most Wanted LQ Wiki articles.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices

Reply
 
Search this Thread
Old 11-07-2005, 05:21 PM   #1
boxerboy
Member
 
Registered: Jul 2005
Distribution: ubuntu5.04, ubuntu5.10, suse9.3, mandrake10.1, mandriva2006(beta), FC1-4, redhat9.0, debian sarge
Posts: 519

Rep: Reputation: 32
shell (bash) scripting question(s)


hi all im dipping toes into the shell scripting world and im already lost. i reading a book its upstairs at moment but im confused i thought shell scripting was all done in shell not in say anjuta for example? i am somewhat familar with C code but this has just lost me. i did create a file it told me to i think it was called "logins" and i only have 3 lines in it not really sure what im doing. i guess my question should be "how do i kno wwhen to put it in terminal or when to put it in program (kdevelop,anjuta).
 
Old 11-07-2005, 05:50 PM   #2
rnicolson
Member
 
Registered: Jul 2004
Location: Winnipeg
Distribution: Slackware 11
Posts: 74

Rep: Reputation: 15
If you are trying to run commands that would normally be run from the shell then you can easily put them into a bash script to be run over and over again. The first line of a bash script must start with;

#!/bin/bash

Anything after that will mostly be commands you can run from a bash prompt. After creating the file you also have to add the executable flag to the script file.

chmod +x filename

will do this for the user who created the script. Then if you want to run the script at set intervals you can have it run in cron or from a command promt type ./filename if you are in the directory holding the file and that directory is not in your path.

I hope this helps.
 
Old 11-07-2005, 09:06 PM   #3
chrism01
Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Centos 6.5, Centos 5.10
Posts: 16,225

Rep: Reputation: 2021Reputation: 2021Reputation: 2021Reputation: 2021Reputation: 2021Reputation: 2021Reputation: 2021Reputation: 2021Reputation: 2021Reputation: 2021Reputation: 2021
The only thing I'd add to the above, is that the #!/bin/bash is a good idea, but FYI, if you don't put it in, the system will use whatever shell is defined in the user's login entry in /etc/passwd.
On Linux this is usually /bin/bash
Hence, you won't always see it specified explicitly in other's code.
 
Old 11-07-2005, 09:14 PM   #4
rnicolson
Member
 
Registered: Jul 2004
Location: Winnipeg
Distribution: Slackware 11
Posts: 74

Rep: Reputation: 15
Good to know chrism01. Thanks for the info.
 
Old 11-08-2005, 12:47 AM   #5
chrism01
Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Centos 6.5, Centos 5.10
Posts: 16,225

Rep: Reputation: 2021Reputation: 2021Reputation: 2021Reputation: 2021Reputation: 2021Reputation: 2021Reputation: 2021Reputation: 2021Reputation: 2021Reputation: 2021Reputation: 2021
Thx ... also,
chmod +x filename.sh gives:
-rwxrwxr-x
perms.. not a good idea. Use
chmod u+x filename.sh
-rwxrw-r--
Ideally you prob want
-rwx------
ie
chmod u=rwx filename.sh
chmod g-rwx filename.sh
chmod o-rwx filename.sh


BTW, on commercial Unices, default shell is prob ksh (korn shell; similar to bash), csh (old) or sh (posix... bit like ksh).
There are several others avail ...
 
Old 11-08-2005, 03:51 PM   #6
boxerboy
Member
 
Registered: Jul 2005
Distribution: ubuntu5.04, ubuntu5.10, suse9.3, mandrake10.1, mandriva2006(beta), FC1-4, redhat9.0, debian sarge
Posts: 519

Original Poster
Rep: Reputation: 32
ok thank you guys the pc is down for now but i had an issue with a chmod command but i have to see it. ill get back to you thank you
 
  


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
Bash shell scripting question. pete1234 Programming 11 09-25-2005 02:59 AM
Bash shell scripting question. Itsu Linux - General 3 04-30-2005 03:52 AM
Bash shell scripting Sco Linux - Newbie 1 11-09-2004 11:58 AM
Bash shell scripting question mehesque Programming 2 07-15-2004 10:54 AM
BASH Shell Scripting Question xianzai Programming 5 03-19-2004 07:50 AM


All times are GMT -5. The time now is 12:38 PM.

Main Menu
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
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration