LinuxQuestions.org
View the Most Wanted LQ Wiki articles.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software
User Name
Password
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.

Notices

Reply
 
Search this Thread
Old 04-09-2007, 05:26 AM   #1
mpooley
Member
 
Registered: Nov 2002
Location: Kings Lynn Norfolk UK
Distribution: obuntu
Posts: 67

Rep: Reputation: 15
trying to learn bash


I am reading a tutorial on bash and the first command i am trying (to set an environmental variable)

doesnt work!
I am typing the command into terminal -- is that right? terminal is bash right?
 
Old 04-09-2007, 05:48 AM   #2
acid_kewpie
Moderator
 
Registered: Jun 2001
Location: UK
Distribution: Gentoo, RHEL, Fedora, Centos
Posts: 43,373

Rep: Reputation: 1962Reputation: 1962Reputation: 1962Reputation: 1962Reputation: 1962Reputation: 1962Reputation: 1962Reputation: 1962Reputation: 1962Reputation: 1962Reputation: 1962
you could maybe tell us what the command you're typing in actually is? we're not psychic.

and a terminal is NOT bah, they are very seperate things. think of a terminal emulator as a black rectangular box with a blinking cursor on it e.g. a car chassis. and bash as the code that actually listens to what you're typing e.g. a car engine. you can run may many different things instead of bash within a terminal, csh, ksh, ash, sh, or somethign that isn't even a shell at all.
 
Old 04-09-2007, 06:11 AM   #3
Valkyrie_of_valhalla
Member
 
Registered: Jan 2006
Location: Romania
Distribution: Suse 12.0, Slackware 12.1, Debian, Ubuntu, Gentoo
Posts: 301

Rep: Reputation: 30
ok, what terminal are you using?
You can also type everything in a terminal, or create a shell script.
To set a variable, you do
variablename="the text of your choice"
And to display it:
echo $variablename

If you want to make a shell script, you have to create a file let's call it filename.sh, which would contain, for example, something like this:
Code:
#!/bin/bash
variablename="hello world"
echo $variablename
Then, in a normal terminal, make that file executable with
chmod 0755 filename.sh
and run it (in a terminal) with
./filename.sh
It should display "hello world"

If you want to learn more about shell scripting, you can check here http://rute.2038bug.com/node10.html....00000000000000
 
Old 04-09-2007, 07:10 AM   #4
Jordi
LQ Newbie
 
Registered: Mar 2007
Location: Barcelona
Distribution: CentOS
Posts: 11

Rep: Reputation: 0
All you need is man bash(1) and a lot of motivation (aka patience+dedicated time).
 
Old 04-09-2007, 10:23 AM   #5
mpooley
Member
 
Registered: Nov 2002
Location: Kings Lynn Norfolk UK
Distribution: obuntu
Posts: 67

Original Poster
Rep: Reputation: 15
Thanks for your help. I think i'm beginning to understand now! i'm a complete newbie so its hard getting your head round shell scripting- terminals etc but i've sorted out that minor problem and i'll be delving into it over the next few weeks - its looks interesting lol
 
Old 04-09-2007, 09:57 PM   #6
jlinkels
Senior Member
 
Registered: Oct 2003
Location: Bonaire
Distribution: Debian Lenny/Squeeze/Wheezy/Sid
Posts: 4,052

Rep: Reputation: 484Reputation: 484Reputation: 484Reputation: 484Reputation: 484
If you do shell scripting, setting an environment variable does not work. As soon as you leave the script, you are back in the parent's environment, and all the variables in the child process (that is what you started your script in) are gone.

Is that your problem?

Did you read the document which is pointed to in my signature?

jlinkels
 
Old 04-10-2007, 03:12 AM   #7
mpooley
Member
 
Registered: Nov 2002
Location: Kings Lynn Norfolk UK
Distribution: obuntu
Posts: 67

Original Poster
Rep: Reputation: 15
Quote:
Originally Posted by jlinkels
If you do shell scripting, setting an environment variable does not work. As soon as you leave the script, you are back in the parent's environment, and all the variables in the child process (that is what you started your script in) are gone.

Is that your problem?

Did you read the document which is pointed to in my signature?

jlinkels
NO i hadnt even got as far as that then ! i was just trying the commands in the tutorial and wasn't sure that using terminal was the right place to do it. I found out that i was just being stupid and typing the $ first which the tutorial showed but didn't explain you shouldn't type it.
Just shows that when giving advice you need to make it Absolutely clear what you mean!! it's too easy to forget that you take a lot of 'obvious' things for granted!

Yes i did go to your link thanks! its a great site and have been using that to write a little script.
Can I ask you about chmod?
chmod 0755 myfile.sh alters the mode of the file to an executable right? ok i did that and it all worked but i like to know what is going on - did it compile a binary when i did that? do you know how that works?
 
Old 04-10-2007, 04:23 AM   #8
Valkyrie_of_valhalla
Member
 
Registered: Jan 2006
Location: Romania
Distribution: Suse 12.0, Slackware 12.1, Debian, Ubuntu, Gentoo
Posts: 301

Rep: Reputation: 30
chmod 0755 simply changes permissions to make it executable. It gives it the permissions rwxr-xr-x.
Nothing is required to be compiled. When you run a script, bash takes it line by line and runs the appropriate programs. (or something like this)

To understand chmod, try "man chmod". You could also have typed in, for example, "chmod a+x myfile.sh", which means make the file executable (x) to everybody (a).
Check here if you want to learn more http://rute.2038bug.com/node17.html....00000000000000
 
Old 04-10-2007, 05:20 AM   #9
mpooley
Member
 
Registered: Nov 2002
Location: Kings Lynn Norfolk UK
Distribution: obuntu
Posts: 67

Original Poster
Rep: Reputation: 15
Thanks Mate!
 
  


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
Good book to learn bash? J_K9 Linux - Newbie 14 11-26-2004 01:38 AM
What is the best book for a beginner to learn his way 'round BASH??? Fabyfakid Linux - Newbie 8 10-15-2004 11:04 PM
Where's the best place to learn Bash? evangelinux Programming 5 06-13-2004 11:45 PM
i want learn bash-script.. i need some resoruces, tutorials.. etc.. hunter_one Linux - General 2 10-29-2003 02:32 PM
New to Linux. Learn bash or C first? kato678 Programming 4 02-20-2002 12:48 PM


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