LinuxQuestions.org
Did you know LQ has a Linux Hardware Compatibility List?
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Distributions > Linux From Scratch
User Name
Password
Linux From Scratch This Forum is for the discussion of LFS.
LFS is a project that provides you with the steps necessary to build your own custom Linux system.

Notices

Reply
 
Search this Thread
Old 05-06-2006, 06:55 PM   #1
linrookie
LQ Newbie
 
Registered: Apr 2006
Posts: 2

Rep: Reputation: 0
Unhappy trouble with positional parameter $0 on bash. linux distro: ubuntu breezy


This is my tutorial script: (word to word from book)
#!/bin/bash
#defining function
afunc () {
echo "in function ${0}: ${1} ${2}"
var1="in function"
}
var1="outside of function"
echo "var1: ${var1}"
echo "${0}: ${1} ${2}"
#calling function
afunc funcarg1 funcarg2
echo "var1: ${var1}"
echo "${0}: ${1} ${2}"

This is the output it generates:
var1: outside of function
myscript: arg1 arg2
in function myscript: funcarg1 funcarg2
var1: in function
myscript: arg1 arg2

In the output I would expect the bolded 'myscript' to be afunc instead since I've already called the function.
Can some one tell me why the $0 won't take up the name of the called function when the other parameters $1 and $2 seem to be recognizing the new arguments?
Any other tips are appreciated too!

TYIA
K
 
Old 05-06-2006, 08:05 PM   #2
gilead
Senior Member
 
Registered: Dec 2005
Location: Brisbane, Australia
Distribution: Slackware64 14.0
Posts: 4,123

Rep: Reputation: 162Reputation: 162
Is that from O'Reilly's "Learning the bash shell"? $0 doesn't change because the function executes in the environment of the shell script and $0 takes the name of the script.
 
Old 05-07-2006, 01:22 PM   #3
linrookie
LQ Newbie
 
Registered: Apr 2006
Posts: 2

Original Poster
Rep: Reputation: 0
Quote:
Originally Posted by gilead
Is that from O'Reilly's "Learning the bash shell"? $0 doesn't change because the function executes in the environment of the shell script and $0 takes the name of the script.

It's actually O'Reilly's 'Learning the Korn Shell'. I'm working on bash though, adapting stuff on the way.

Somehow the $1 and $2 accept the function's(with in the script) arguments. According to the book $0 would change too to the name of the function it's being called from.

Appreciate the help.
K
 
  


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
need ubuntu breezy upgrade help eoinmonty Ubuntu 2 02-24-2006 11:00 PM
i865G on ubuntu breezy eantoranz Linux - Hardware 0 01-02-2006 01:17 PM
bash parameter indirection possible? kornelix Programming 5 11-30-2005 09:35 AM
bash: pass a parameter to xview nimra Programming 2 06-28-2004 10:18 PM
Bash function parameter Misel Programming 2 05-17-2003 12:51 PM


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

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