I have a Bash Script and an Expect script that together will SSH to another server and
do some stuff there... From within the Bash Script I process the Command Line Arguments,
which are Required Args and Optional Args.
When I call the Expect script from the Bash Script, I pass it all the required Args as
there own variables: i.e. $ip_address, $username, $password, $option...
Then, as I process any Optional Arguments I want to concatenate them into one Variable. Doing this
will remove a whole bunch of If statements from my script that would, for example, if the optional
argument "--restart" was given then execute the Expect Script with all the Required Args then
add the Optional Arg "--restart" to the end of the line that executes the script:
So I would have to do this sort of thing for each optional argument, which could get very messy
because most of the Optional Args can be used together, which means a bunch of different combinations of Args can be used,
leaving me with a bunch of if statements...
So now what I have is, as I am checking all the Args from the command line, in the Bash Script... If
I find for example the "--restart" option I would say:
Then I find the "add" option, I do:
Lastly, I give it this final Arg:
Now I only have to have one line that makes a Call to the Expect Script like this...
(fyi when I make the call to execute the Expect script I add one last required option to the end of the line):
Now, while in the Expect Script I did a simple loop to check all the Args passed in and it seems it's treating the
Args within the variable "$exe_command_args" as one command line argument.
Here's the Loop from the Expect Script, and the Output:
So could there be anything I am doing wrong syntactically in the bash script when passing the
arguments? I was under the assumption that in order for an argument to be considered ONE arg,
if it contained any whitespace, that it needed to be quoted..?
And if I look at the Expect Output it seems to be quoted correctly and everything.
If anyone has anythoughts that would be great!
I really didn't want to have to change anything in the Expect Script of that way it assigns the
arguments to the variables...
***Sorry if I made this a little more confusing/complicated then it needed to be...
Hi,
I am new to unix. Is their a way to pass the output of the line below to a variable var1.
ls -1t | head -1.
I am trying something like var1=ls -1t | head -1, but I get error.
Situation is: I get file everyday through FTP in my unix box. I have to write a script that picks up first... (1 Reply)
My program usage takes the form for example;
$ theApp 2 "one or more words"
i.e. 3 command line arguments; application name, an integer, some text
My code includes the following 4 lines:
int anInteger;
char words;
sscanf(argv, "%d", &anInteger);
sscanf(argv, "%s", &message);
Based... (2 Replies)
I am trying to print command line arguments one per second. I have this
while
do
echo "6"
shift
echo "5"
shift
echo "4"
shift
echo "3"
shift
echo "2"
shift
echo "1"
shift
done (2 Replies)
I have this while loop and at the end I am trying to get it to tell me the last argument I entered. And with it like this all I get is the sentence with no value for $1. Now I tried moving done after the sentence and it printed the value of $1 after every number. I don't want that I just want... (2 Replies)
Hi,
I have to store all the command line arguments into an array.
I have the following code.
**********************
#! /bin/sh
set -A arr_no_updates
i=1
while
do
arr_no_updates=$($i)
echo ${arr_no_updates}
i=$(($i+1))
done**************** (1 Reply)
Hi,
i have a perl script named test.pl. It is executed as
cat *.log|test.pl
i need the complete command line args. I tried using basename $0 but im getting test.pl only but not cat *.log...
Can anyone help me on this.
Thanks in advance (3 Replies)
Hi,
Can you please hint me how to achieve the below?
Input:
$./script.sh start 1 2
Internally inside the script i want to set a single variable with $2 and $3 value?
Output:
CMD=$1
ARGS=$2 $3
--VInodh (10 Replies)
Hi All,
Below is a sample command that I can run without any problem in the command line.
Command Line
dtToday=`date +%Y%m%d`; ls -ltr ./filename_${dtToday}.txt
-rw-r--r-- 1 monuser oinstall 0 Jan 18 11:02 ./filename_20130118.txt
But once I put that command line in file (list.txt) and... (3 Replies)
Hi,
I am calling a Perl script in my shell script. When Perl script is executed it asks for a answer to be entered by user from terminal. How can i pass that value from my shell script ??
I know I can change perl script to default the answer but i dont have access to do that so only option i... (5 Replies)