LinuxQuestions.org
Go Job Hunting at the LQ Job Marketplace
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 03-01-2012, 03:39 AM   #1
thomas2004ch
Member
 
Registered: Aug 2009
Posts: 499

Rep: Reputation: 31
A bash-script question: parameter hand up


Hi,

One of my script looks as follow:
error.sh
Code:
#!/bin/sh

function error()
{

echo $1
echo $2
}
The second one calls the first ine as follow:
test.sh
Code:
#!/bin/sh

. ./error.sh

ERRORNUM="11"
ERRORDAT="number 1"

error $ERRORNUM $ERRORDAT
As I run the test.sh I got:
Code:
$1=11
$2=number
This means the $2 is wrong.

What could be the problem?
 
Old 03-01-2012, 03:52 AM   #2
catkin
LQ 5k Club
 
Registered: Dec 2008
Location: Tamil Nadu, India
Distribution: Servers: Debian Squeeze and Wheezy. Desktop: Slackware64 14.0. Netbook: Slackware 13.37
Posts: 8,546
Blog Entries: 28

Rep: Reputation: 1176Reputation: 1176Reputation: 1176Reputation: 1176Reputation: 1176Reputation: 1176Reputation: 1176Reputation: 1176Reputation: 1176
You need to double quote:
Code:
error $ERRORNUM "$ERRORDAT"
to avoid bash splitting it into two separate words which become $2 and $3 for the function.
 
1 members found this post helpful.
Old 03-01-2012, 06:46 AM   #3
thomas2004ch
Member
 
Registered: Aug 2009
Posts: 499

Original Poster
Rep: Reputation: 31
indeed. many thanks!
 
  


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
[SOLVED] bash variable as parameter to script atomicdog Linux - Newbie 8 05-16-2011 02:49 AM
bash script position parameter does is not parsing '$1' junust Programming 5 04-08-2010 07:50 PM
bash script for selecting a parameter from list of parameters m4rtin Programming 9 12-21-2009 09:41 AM
Conditional (IF) test in bash sh script - presence of first parameter Critcho Linux - Newbie 6 10-01-2008 12:20 AM
bash programming question - hand over variables to another script ppr:kut Linux - General 5 02-09-2008 10:00 AM


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