- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- Shell Scripting Question
Categories
Company
Local Language
Forums
Discussions
Forums
- Data Protection and Retention
- Entry Storage Systems
- Legacy
- Midrange and Enterprise Storage
- Storage Networking
- HPE Nimble Storage
Discussions
Forums
Discussions
Discussions
Discussions
Forums
Discussions
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
- BladeSystem Infrastructure and Application Solutions
- Appliance Servers
- Alpha Servers
- BackOffice Products
- Internet Products
- HPE 9000 and HPE e3000 Servers
- Networking
- Netservers
- Secure OS Software for Linux
- Server Management (Insight Manager 7)
- Windows Server 2003
- Operating System - Tru64 Unix
- ProLiant Deployment and Provisioning
- Linux-Based Community / Regional
- Microsoft System Center Integration
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Community
Resources
Forums
Blogs
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-30-2008 11:35 AM
06-30-2008 11:35 AM
Shell Scripting Question
Coming to the question ..
I am looking for a command which will substitute the arguments given to a command.
i.e.
If I execute that command this way,
It should produce an output by replacing references to $1 as
I can think of an "sed" solution. But I am looking for something smaller and simpler.
Regards,
Kaps
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-30-2008 12:07 PM
06-30-2008 12:07 PM
Re: Shell Scripting Question
But "echo" will do that
$> echo one two three four five six
one two three four five six
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-30-2008 12:51 PM
06-30-2008 12:51 PM
Re: Shell Scripting Question
if [ $1 -eq 100 ]
then
echo "It was hundred "
fi
And you execute
The output should be
if [ 10 -eq 100 ]
then
echo "It was hundred "
fi
I am looking for a script to replace "command"
Regards,
Kaps
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-30-2008 01:01 PM
06-30-2008 01:01 PM
Re: Shell Scripting Question
While it's not a script (its just a shell command option), this will get you close.
$> set -x
and then run your script.
It will show you what you are looking for.
An example to see if process id of the current shell is equal to 37.
$> echo [ $$ -eq 37 ]|| echo yes && echo no
+ echo '[' 7670 -eq 37 ']'
[ 7670 -eq 37 ]
+ echo no
no
An easy way to do this is just to put a
"set -x" command near the top of your script, and comment it out when you don't need it any longer.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-30-2008 01:13 PM
06-30-2008 01:13 PM
Re: Shell Scripting Question
Regards,
Kaps
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-30-2008 01:18 PM
06-30-2008 01:18 PM
Re: Shell Scripting Question
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-30-2008 01:30 PM
06-30-2008 01:30 PM
Re: Shell Scripting Question
> I am also going to believe that my question is really a stupid one. $1 , $2 kind of variables makes sense only when I execute it ..
From that perspective, make your script self-documenting:
# cat somescript
#!/usr/bin/sh
typeset WHO=$1
typeset WHERE=$2
echo "I said hello ${WHERE} ${WHO}"
# ./somescript Kaps there
I said hello there Kaps
Regards!
...JRF...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-30-2008 01:52 PM
06-30-2008 01:52 PM
Re: Shell Scripting Question
Hi JRF,
In the example you gave, I was expecting an output like ,
# cat somescript
#!/usr/bin/sh
typeset WHO=kapil
typeset WHERE=
echo "I said hello ${WHERE} ${WHO}"
I think it is an sed question i.e. ,
cat myscript | sed "s;$1;arg1;g" .. .. , I think I have to do it that way.
Regards,
Kaps
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-30-2008 02:20 PM
06-30-2008 02:20 PM
Re: Shell Scripting Question
> I think it is an sed question i.e. ...cat myscript | sed "s;$1;arg1;g" .. .. , I think I have to do it that way
Well, if that's what you really want, at least don't run the useless 'cat' process and fix the replacement:
# sed 's;$1;arg1;g' file
(or)
# sed "s;\$1;arg1;g" file
...but the use of a semicolon as a delimiter is limiting since you might want to make one pass and do:
# sed "s/\$1/arg1/g;s/\$2/arg2/g" file
(or):
# sed 's/$1/arg1/g;s/$2/arg2/g' file
Please note that I am still unsure as to what is your real objective.
Regards!
...JRF...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-01-2008 12:51 AM
07-01-2008 12:51 AM
Re: Shell Scripting Question
I'm still not sure what you want??
>i.e. If I execute that command this way,
>It should produce an output by replacing references to $1 as
If you want to change $1, etc, you can use set:
set
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-31-2009 04:05 PM
03-31-2009 04:05 PM
Re: Shell Scripting Question
Closing the thread ..