LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 06-14-2007, 06:58 PM   #1
khanrockz
LQ Newbie
 
Registered: Feb 2007
Posts: 13

Rep: Reputation: 0
bash wrapper arguments problem ...


Hi !
I am trying to write a wrapper for ssh and it seems that it is not interpreting the arguments that are passed to it. The code for the wrapper goes like :

Code:
invoknam=`basename $0`
function make_command_line_args2 () {

    for (( i = 1; i <= $# ; i++ ))
    do
        eval VAR=\$$i
        countargs $VAR
        words=$?
        if [ "$words" -ge "2" ] ; then
                OPTIONS="$OPTIONS \"$VAR\""
        else
                OPTIONS="$OPTIONS $VAR"
        fi
    done
    echo $OPTIONS
}

cmd2=$(make_command_line_args2 "$@")
echo Command Options : $cmd2
exec /usr/bin/$invoknam $cmd2
but when I execute it it gives

khan /bin> ssh -x "-oForwardAgent no" khan@192.168.0.1
Command Options : -x "-oForwardAgent no" khan@192.168.0.1
ssh: "-oForwardAgent: Name or service not known

So it seems that i am getting the quotes right but they are not interpreted as I want them to. This command is a valid command with normal ssh executable.
Any help will be greatly appreciated ... how can I make this work ? Where am I going wrong ?
 
Old 06-15-2007, 03:32 AM   #2
gnashley
Amigo developer
 
Registered: Dec 2003
Location: Germany
Distribution: Slackware
Posts: 4,928

Rep: Reputation: 612Reputation: 612Reputation: 612Reputation: 612Reputation: 612Reputation: 612
This should get the second argument for you:
echo "$@" | awk '{ print $2}'
 
Old 06-15-2007, 10:44 AM   #3
khanrockz
LQ Newbie
 
Registered: Feb 2007
Posts: 13

Original Poster
Rep: Reputation: 0
Quote:
This should get the second argument for you:
echo "$@" | awk '{ print $2}'
But how does this help in my code ? Can u plz be a little more specific. I am sorry but am a newbie .
 
Old 06-15-2007, 11:38 AM   #4
druuna
LQ Veteran
 
Registered: Sep 2003
Posts: 10,532
Blog Entries: 7

Rep: Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405
Hi,

Maybe the above is an exercise in programming (which I doubt) or maybe I'm missing the point, but the code below does what you want without all the extra de-assembling and re-assembling of the command line options:
Code:
#!/bin/bash

echo Command Options : "$@"
exec /usr/bin/ssh "$@"
An example run:
Code:
 $ ./ssh.sh -x "-oForwardAgent no" druuna@xxxx.yyyy.zzzz
Command Options : -x -oForwardAgent no druuna@xxxx.yyyy.zzzz
Password:
Hope this helps.
 
  


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
bash history - replacing arguments Vrajgh Linux - Software 4 03-08-2006 02:36 AM
bash, passing arguments Four Linux - Newbie 3 02-06-2006 08:24 AM
Bash: how to write a wrapper script? J_Szucs Programming 0 01-29-2005 05:50 PM
Wrapper needed for BASH Script outspoken Programming 0 01-12-2005 09:04 AM
bash arguments stuckinhell Programming 6 08-13-2004 05:10 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 02:31 PM.

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