LinuxQuestions.org
Register a domain and help support LQ
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 12-01-2012, 01:47 PM   #1
Ztcoracat
Senior Member
 
Registered: Dec 2011
Distribution: Slackware, CentOS & Android
Posts: 3,186
Blog Entries: 1

Rep: Reputation: Disabled
First Script and bin directory


Hi:

This is my first script and I know it probably has errors but I am trying to understand. I used gedit to make it. I have read this article to help http://www.linuxcommand.org/wss0010.php

Code:
#!/bin/bash
#my first script 
echo "Hello World!"
chmod 755 my_script
./my_script
echo $PATH
export PATH=$PATH:documents
mkdir bin
my_script
Where the line that says export PATH=$PATH: Is this where I put the path to my script in my documents?
ztcoracat/documents/my_script?

And the line for mkdir bin; if I make a new directory is there only one bin that it will be dedicated to?

Does my script have to be named 'my_script"?
Can it be named my_firstscript1?

The instructions say to move my script into my new bin directory.
Where are new bin directories located? In the Home folder?

Last edited by Ztcoracat; 12-01-2012 at 01:52 PM.
 
Old 12-01-2012, 03:01 PM   #2
linosaurusroot
Member
 
Registered: Oct 2012
Distribution: OpenSuSE,RHEL,Fedora,OpenBSD
Posts: 808
Blog Entries: 2

Rep: Reputation: 203Reputation: 203Reputation: 203
Your script could look like this
Code:
#!/bin/bash
#my first script 
echo "Hello World!"
echo $PATH
and your commands run outside the script could look like this
Code:
chmod 755 my_script
./my_script
echo $PATH
export PATH=$PATH:~/bin
echo $PATH
mkdir bin
mv my_script bin/
my_script
 
1 members found this post helpful.
Old 12-01-2012, 06:23 PM   #3
Ztcoracat
Senior Member
 
Registered: Dec 2011
Distribution: Slackware, CentOS & Android
Posts: 3,186
Blog Entries: 1

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by linosaurusroot View Post
Your script could look like this
Code:
#!/bin/bash
#my first script 
echo "Hello World!"
echo $PATH
and your commands run outside the script could look like this
Code:
chmod 755 my_script
./my_script
echo $PATH
export PATH=$PATH:~/bin
echo $PATH
mkdir bin
mv my_script bin/
my_script
Thanks for showing me what belongs in the script it's self and what I'd run in the terminal.

How or where can I learn and read more to understand?

I'm asking because I need to learn how to write a script for 2 cron jobs to run and I still don't understand even after reading all this that a moderator posted for me.
I've read through all of this documentation and Bash scripting is still foreign to me.
http://www.tldp.org/
http://tldp.org/LDP/Bash-Beginners-G...tml/index.html
http://www.gnu.org/software/bash/manual/bashref.html
http://www.webring.org/hub/linux?w=1...hat-linux;rd=1
I didn't read through the Advanced Bash Scripting Guides because I'm still struggling with basic scripting-

Would going and learning Perl help me anymore in understanding Bash?

What else can you recommend?

Last edited by Ztcoracat; 12-01-2012 at 06:31 PM. Reason: Additional questions
 
Old 12-01-2012, 06:54 PM   #4
PTrenholme
Senior Member
 
Registered: Dec 2004
Location: Olympia, WA, USA
Distribution: Fedora, (K)Ubuntu
Posts: 4,151

Rep: Reputation: 331Reputation: 331Reputation: 331Reputation: 331
Go to the Programming forum and look at the bash scripting questions and answers. Also, try the pinfo bash command for a useful on-line reference. (Depending on your distribution, you may need to install the pinfo command, or just use the older info command.) Often whilst I program a bash script, I keep the pinfo bash output in a tab on my terminal emulator so I can refer to it as needed.

You could also look at the scripts in /etc/cron.*/ to see how they are written.

Consider asking the forum moderator(s) to move you thread into the Programming forum. (You can make the request by "reporting" your thread - there should be a button at the bottom of your first post.)
 
1 members found this post helpful.
Old 12-01-2012, 07:02 PM   #5
linosaurusroot
Member
 
Registered: Oct 2012
Distribution: OpenSuSE,RHEL,Fedora,OpenBSD
Posts: 808
Blog Entries: 2

Rep: Reputation: 203Reputation: 203Reputation: 203
Perl is a great language but it wouldn't help you much with bash.

Programming needs to be learned by doing it - and having exercises that are actual small (to start with) things you want programmed.
 
1 members found this post helpful.
Old 12-01-2012, 07:05 PM   #6
Ztcoracat
Senior Member
 
Registered: Dec 2011
Distribution: Slackware, CentOS & Android
Posts: 3,186
Blog Entries: 1

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by PTrenholme View Post
Go to the Programming forum and look at the bash scripting questions and answers. Also, try the pinfo bash command for a useful on-line reference. (Depending on your distribution, you may need to install the pinfo command, or just use the older info command.) Often whilst I program a bash script, I keep the pinfo bash output in a tab on my terminal emulator so I can refer to it as needed.

You could also look at the scripts in /etc/cron.*/ to see how they are written.

Consider asking the forum moderator(s) to move you thread into the Programming forum. (You can make the request by "reporting" your thread - there should be a button at the bottom of your first post.)
Thanks for enlightening me. I was unaware of 'pinfo bash'
My distro is Debian 6.0.5 Stable Squeeze AMD 64bit-

Reading through the Programming Forum is not helping but I just started so I will give it a chance. Thanks for the good advice.

Last edited by Ztcoracat; 12-01-2012 at 07:10 PM. Reason: Additional thought-
 
Old 12-01-2012, 07:24 PM   #7
Ztcoracat
Senior Member
 
Registered: Dec 2011
Distribution: Slackware, CentOS & Android
Posts: 3,186
Blog Entries: 1

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by linosaurusroot View Post
Perl is a great language but it wouldn't help you much with bash.

Programming needs to be learned by doing it - and having exercises that are actual small (to start with) things you want programmed.
Agreed-
I hope to find more exercises that are small that I can grasp-

I'll check in my "The Debian Administrators Handbook" as there might be a few chapters that discuss Bash-
 
Old 12-04-2012, 05:51 PM   #8
Ztcoracat
Senior Member
 
Registered: Dec 2011
Distribution: Slackware, CentOS & Android
Posts: 3,186
Blog Entries: 1

Original Poster
Rep: Reputation: Disabled
I found these differnt entries for Bash after the hashbang and am wondering why is the command interpreter different when these are used?

#!bin/bash
#!bin/sh
#usr/bin/perl
#!usr/awk

I looked in etc/cron.d to learn from the file. It's output is:
Code:
CRON.d 
# /etc/cron.d/anacron: crontab entries for the anacron package

SHELL=/bin/sh
PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin

30 7    * * *   root	test -x /etc/init.d/anacron && /usr/sbin/invoke-rc.d anacron start >/dev/null
I have read this file several times but still do not understand how to write a shell script for rkhunter and chkrootkit that I would like an executable script to run. Otherwise I have been opening the terminal and running these applications manually.
Any suggestions?
 
Old 12-04-2012, 07:37 PM   #9
linosaurusroot
Member
 
Registered: Oct 2012
Distribution: OpenSuSE,RHEL,Fedora,OpenBSD
Posts: 808
Blog Entries: 2

Rep: Reputation: 203Reputation: 203Reputation: 203
Quote:
Originally Posted by Ztcoracat View Post
I found these differnt entries for Bash after the hashbang and am wondering why is the command interpreter different when these are used?

#!bin/bash
#!bin/sh
#usr/bin/perl
#!usr/awk

These are different programs. And you're missing the first / after #!
 
Old 12-04-2012, 09:40 PM   #10
Ztcoracat
Senior Member
 
Registered: Dec 2011
Distribution: Slackware, CentOS & Android
Posts: 3,186
Blog Entries: 1

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by linosaurusroot View Post
These are different programs. And you're missing the first / after #!
Since they are different programs how do I know which one is appropriate for the task I wish to accomplish or run?

Got it; like this:

#!/bin/sh
#!/bin/bash

Last edited by Ztcoracat; 12-04-2012 at 09:43 PM.
 
Old 12-05-2012, 07:03 AM   #11
onebuck
Moderator
 
Registered: Jan 2005
Location: Midwest USA, Central Illinois
Distribution: SlackwareŽ
Posts: 11,293
Blog Entries: 3

Rep: Reputation: 1448Reputation: 1448Reputation: 1448Reputation: 1448Reputation: 1448Reputation: 1448Reputation: 1448Reputation: 1448Reputation: 1448Reputation: 1448
Moderator Response

Moved: This thread is more suitable in <Programming> and has been moved accordingly to help your thread/question get the exposure it deserves.
 
1 members found this post helpful.
Old 12-05-2012, 10:15 AM   #12
Ztcoracat
Senior Member
 
Registered: Dec 2011
Distribution: Slackware, CentOS & Android
Posts: 3,186
Blog Entries: 1

Original Poster
Rep: Reputation: Disabled
Thanks; Onebuck!
 
Old 12-05-2012, 10:18 AM   #13
Ztcoracat
Senior Member
 
Registered: Dec 2011
Distribution: Slackware, CentOS & Android
Posts: 3,186
Blog Entries: 1

Original Poster
Rep: Reputation: Disabled
Where in the script would I type my explanation of the purpose of the script?

For example:
This script is for cron jobs to run rkhunter and chkrookit @ 8 o'clock p.m. every Friday to make certain that there are not any root kits on my system-
Before or after the PATH?
And where should the PATH start from the /usr/bin or etc/cron?

Last edited by Ztcoracat; 12-05-2012 at 10:24 AM.
 
Old 12-07-2012, 01:58 PM   #14
Ztcoracat
Senior Member
 
Registered: Dec 2011
Distribution: Slackware, CentOS & Android
Posts: 3,186
Blog Entries: 1

Original Poster
Rep: Reputation: Disabled
Bash script or Terminal

Is this argument suitable for a script?

Quote:
run rkhunter_1.3.6-4 and chkrootkit_0.49-4 every Friday at 8 O'clock p.m.?
 
Old 12-13-2012, 01:02 PM   #15
Ztcoracat
Senior Member
 
Registered: Dec 2011
Distribution: Slackware, CentOS & Android
Posts: 3,186
Blog Entries: 1

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by Ztcoracat View Post
Is this argument suitable for a script?
Anyone?

Is there anywhere else I could go to better understand scripting?
And would learning C programming or C+ make Bash scripting make any more sense to me?
 
  


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
could not execute bin folder of a package from cgi bin script using python ashish hasani Linux - Server 1 04-05-2012 12:18 AM
[SOLVED] "!#/bin/bash: No such file or directory"? When running a script C_Blade Linux - Newbie 12 04-08-2010 10:15 PM
[SOLVED] #!/bin/sh vs #!/bin/bash -- script executes differently; each way = different bugs GrapefruiTgirl Programming 21 12-16-2009 05:30 PM
cgi-bin: "attempt to invoke directory as script" hamish Linux - Software 0 12-09-2004 12:45 PM
bin/bash:usr/bin/lpr NO SUCH FILE OR DIRECTORY Adibe_Hamm Linux - Newbie 3 10-14-2003 02:30 AM


All times are GMT -5. The time now is 10:50 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