LinuxQuestions.org
Help answer threads with 0 replies.
Home Forums Tutorials Articles Register
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, 05: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, 07:05 PM   #2
gilead
Senior Member
 
Registered: Dec 2005
Location: Brisbane, Australia
Distribution: Slackware64 14.0
Posts: 4,141

Rep: Reputation: 168Reputation: 168
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, 12: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



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

LinuxQuestions.org > Forums > Linux Forums > Linux - Distributions > Linux From Scratch

All times are GMT -5. The time now is 09:34 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
Open Source Consulting | Domain Registration