Operating System - HP-UX
1827293 Members
3575 Online
109717 Solutions
New Discussion

command in script - parameters

 
SOLVED
Go to solution
Jairo Campana
Trusted Contributor

command in script - parameters

Hello , I have:
TEST='*blinker@yahoo.com'

I need to send like parameters to another command(inyec) , the name user and domain without @
ex command manually:
inyec -l reinstall -u "*binker" -d "yahoo.com"

since I can do it in my script.

Thanks

legionx
12 REPLIES 12
A. Clay Stephenson
Acclaimed Contributor

Re: command in script - parameters

TEST="blinker@yahoo.com"

echo "${TEST}" | awk -F '@' '{print $1,$2}' | read NAME DOM
inyec -l reinstall -u "${NAME}" -d "${DOM}"
If it ain't broke, I can fix that.
Peter Godron
Honored Contributor

Re: command in script - parameters

TEST="*blinker@yahoo.com"

echo "${TEST}" | tr '@' ' ' | read NAME DOM
inyec -l reinstall -u "${NAME}" -d "${DOM}"
Jairo Campana
Trusted Contributor

Re: command in script - parameters

Clay obtaing error:
echo "${TEST}" | awk -F '@' '{print $1,$2}' | read NAME DOM
awk: syntax error near line 1
awk: bailing out near line 1
legionx
Stephen Keane
Honored Contributor
Solution

Re: command in script - parameters

As we've had awk and tr, that just leaves sed and perl

inyec -l reinstall `echo "$TEST" | sed -e 's/^/-u "/' -e 's/@/" -d "/' -e 's/$/"/'`

I'll leave perl to someone else

Peter Godron
Honored Contributor

Re: command in script - parameters

Jairo,
have attached shell script that test first two answers.

Regards
A. Clay Stephenson
Acclaimed Contributor

Re: command in script - parameters

I don't see anything wrong. You did enclose {print $1,$2} in single quotes?
If it ain't broke, I can fix that.
Jairo Campana
Trusted Contributor

Re: command in script - parameters

Peter ANSW1 NO WORK ANSW2 no work:
USING set -x in the script obtaing:

ANWS1:
++ echo '*jairo@speedy.com.ar'
++ awk -F '@{print $1,$2}'
++ NAME DOM
awk: ./TESTO.sh: NAME: command not found
syntax error near line 1
awk: bailing out near line 1
++ inyec -l reinstall -u '' -d ''

ANWS2:
echo '*jairo@speedy.com.ar'
++ tr @ ' '
++ read NAME DOM
++ inyec -l reinstall -u '' -d ''

legionx
Jairo Campana
Trusted Contributor

Re: command in script - parameters

yes clay enclose {print $1,$2} in single quotes:}
echo "${TEST}" | awk -F '@' '{print $1,$2}' | read NAME DOM
legionx
Jairo Campana
Trusted Contributor

Re: command in script - parameters

excelent, Stephen:
ITS work:

`echo "$TEST" | sed -e 's/^/-u "/' -e 's/@/" -d "/' -e 's/$/"/'`

THANKS
legionx
Peter Godron
Honored Contributor

Re: command in script - parameters

Jairo,
just as a thought why the first two options do not work for you, but work on my platform.
What OS are you running?
Regards
Jairo Campana
Trusted Contributor

Re: command in script - parameters

yes Peter my platform is solaris
In hpux too work ANSW1 Y ANSW2

SUBMITED POINT for Klay and Peter
legionx
A. Clay Stephenson
Acclaimed Contributor

Re: command in script - parameters

I think the problem is that under Solaris you need to change awk to nawk (new awk). Under HP-UX awk is nawk but under Solaris awk is oawk (old awk). The funny thing is that nawk (new awk) is now about 20 years old.
If it ain't broke, I can fix that.