use $1 parameter


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting use $1 parameter
# 1  
Old 03-04-2009
use $1 parameter

Hi,

I have a script and I'm passing in a parmeter $1, and I only what to pass this $1 parmeter into another script.

Please see below for details for help :

Code:
virtual_gateway="$1"
YYYYMMDD="`date +%Y%m%d`"

        STARTUP_LOG="/$virtual_gateway/FIXGW/var/log/${virtual_gateway}_query_logwatcher.startup.${YYYYMMDD}.log"
        echo Attempting to start \"$1 Logwatcher\" at `date` >> $STARTUP_LOG
        ./shared/version >> $STARTUP_LOG 2>&1
        nohup ./shared/runManagedLogwatcher_pid ${virtual_gateway}_query >> $STARTUP_LOG 2>&1 &
 
But when I run this 1st script, which call's runManagedLogwatcher_pid, it passes $1_query.

Please could someone help so it only uses $1 parmeter.

regards

venhart
# 2  
Old 03-04-2009
You will need to remove the quotes around the $1 when assigning its value to another variable.

virtual_gateway=$1 not "$1"
# 3  
Old 03-04-2009
Once I removed the quotes around the $1, how can I assign it to another variable so the script that I call - runManagedLogwatcher_pid only uses $1, instead of ${virtual_gateway}_query.

regards,

venhart
# 4  
Old 03-04-2009
I am not quite following you there. If you pass $1 to the first script and then call a second script passing it the $1 value then the 2nd script will refer to the $1 value as $1.

I invoke first script passing it "1234"

myshell.sh 1234

in myshell.sh I have these two lines

passvar=$1

myshell2.sh ${passvar}

Then in myshell2.sh I have the following line

passvar=$1

so if you echo $passvar in myshell2.sh it should display 1234.

Is that what you are looking for?
# 5  
Old 03-04-2009
Otherwise sign it to a variable and export that variable so the other script can use it.

For example

virtual_gateway=$1
PASSVAR=$1
export PASSVAR

this should allow you to use PASSVAR as $1 in all subsequent shells.
# 6  
Old 03-04-2009
Hi,

in my first script I have the following :

virtual_gateway=$1
PASSVAR=$2
export PASSVAR
YYYYMMDD="`date +%Y%m%d`"


STARTUP_LOG="/$virtual_gateway/FIXGW/var/log/${virtual_gateway}_${PASSVAR}_logwatcher.startup.${YYYYMMDD}.log"
echo Attempting to start \"$1 Logwatcher\" at `date` >> $STARTUP_LOG
./shared/version >> $STARTUP_LOG 2>&1
nohup ./shared/runManagedLogwatcher_pid ${virtual_gateway} >> $STARTUP_LOG 2>&1 &

and in my second script I have :

config="managed/data/config/ttalert.xml"
name="${APPLICATION}_$PASSVAR_logwatcher"

echo "running Reuters Targeted Messaging $APPLICATION Logwatcher..."

cd $TT_HOME/bin
CMD="./runTTAlert -config $config -mhost $MGMT_SERVER -mport 9876 -mcache /$1/FIXGW/var/mcache-$name -name $name"

echo EXECUTING $CMD

and when I check my logs, it still errors as the command in the second script looks like :

CMD=./runManagedLogwatcher_pid -config managed/data/config/ttalert.xml -mhost 10.128.13.9 -mport 9876 -mcache /NMHFIXGateway01/F
IXGW/var/mcache-NMHFIXGateway01_ -name NMHFIXGateway01_

The call command I'm using is scriptname NMHFIXGateway01 query

I would need to see within the CMD prompt : NMHFIXGateway01_query
# 7  
Old 03-04-2009
The call command should be NMHFIXGateway01_query
instead of
The call command I'm using is scriptname NMHFIXGateway01 query
this command would use NMHFIXGateway as $1 and query and $2

or
in the second script where the $PASSVAR is change to ${PASSVAR}_query

I would need to see within the CMD prompt : NMHFIXGateway01_query

or in first script

PASSVAR=$1"_"$2
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Use parameter expansion over a parameter expansion in bash.

Hello All, Could you please do help me here as I would like to perform parameter expansion in shell over a parameter expansion. Let's say I have following variable. path="/var/talend/nat/cdc" Now to get only nat I could do following. path1="${path%/*}" path1="${path1##*/}" Here... (8 Replies)
Discussion started by: RavinderSingh13
8 Replies

2. Shell Programming and Scripting

Call Script with Parameter (that has another parameter)

Hi. How do I achieve this sh /EDWH-DMT02/script/MISC/exec_sql.sh "@/EDWH-DMT02/script/others/CSM_CKC/Complete_List.sql ${file_name}" Complete_List.txt The /EDWH-DMT02/script/MISC/exec_sql.sh has two parameters and it's working fine with this sh /EDWH-DMT02/script/MISC/exec_sql.sh... (7 Replies)
Discussion started by: aimy
7 Replies

3. Shell Programming and Scripting

Resolving a parameter which is passed as parameter

Hi, I have the following files. ->cat scr.sh export TMP_DIR=/home/user/folder1 export TMP_DIR_2=/home/user/folder2 while read line do cat "$line" done<file_list.dat ------------------------ -> cat file_list.dat $TMP_DIR/file1.txt $TMP_DIR_2/file2.txt --------------------------- -> cat... (6 Replies)
Discussion started by: barath
6 Replies

4. Shell Programming and Scripting

How to get the parameter value from the parameter file in perl?

hi all, i have a parameter file of following format, i want a method which can get the value of specific parameter. parameter file format: <Parameter Name="FileLocationWindows"> <Description> The directory location of the logger file. ... (1 Reply)
Discussion started by: laxmikant.hcl
1 Replies

5. Shell Programming and Scripting

Passing parameter to script, and split the parameter

i am passing input parameter 'one_two' to the script , the script output should display the result as below one_1two one_2two one_3two if then echo " Usage : <$0> <DATABASE> " exit 0 else for DB in 1 2 3 do DBname=`$DATABASE | awk -F "_" '{print $1_${DB}_$2}` done fi (5 Replies)
Discussion started by: only4satish
5 Replies

6. Shell Programming and Scripting

Command that takes one parameter and then searches for the passed in parameter

Hi I am looking for a unix command or a small shell script which can takes one parameter and then searches for the passed in the parameter in any or all files under say /home/dev/ Can anyone please help me on this? (3 Replies)
Discussion started by: pankaj80
3 Replies

7. UNIX for Dummies Questions & Answers

how to get $1 parameter in ~/.bashrc

Hi, i am trying to convert windows path to linux and do some action on equivalent mounted one for the same in linux. echo '\\server1\source\path\needed_files' | sed -e 's!\\!/!g' | sed -e 's!^//!/!' | sed -e 's!\(/server1/source/path\)\(.*\)!/home/$USER/mount/server1\2!'output: ... (5 Replies)
Discussion started by: greet_sed
5 Replies

8. Shell Programming and Scripting

how do I make dynamic parameter names? Or get the value of a parameter evaluated twi

Say I write something like the following: var1=1 var2=2 for int in 1 2 do echo "\$var$int" done I want the output to be: 1 2 Instead I get something like: $var1 $var2 (2 Replies)
Discussion started by: Awanka
2 Replies

9. Shell Programming and Scripting

parameter

I need to pass a filename parameter in shell script and then need to validate same name in the folder, Can any one help what would be piece of code to do so. Lets folder is a and file with a is test.dat and i want to pass this parameter against the file name file_name and then want to compare... (5 Replies)
Discussion started by: u263066
5 Replies

10. UNIX for Dummies Questions & Answers

$- parameter ...

I have an excert from the Rute Tutorial and Expo by paul sheer... about parameters.. so far I have understood most of them .. except this one: "$- Expands to the current option flags as specified upon invocation, by the set builtin command, or those set by the shell itself (such as the -i... (2 Replies)
Discussion started by: moxxx68
2 Replies
Login or Register to Ask a Question