- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- Passed Parameters and Spaces
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
Discussions
Discussions
Forums
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
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
тАО04-16-2009 03:50 AM
тАО04-16-2009 03:50 AM
I have the following script:
echo "**************** in scriptmcr001 $#"
for p in "$@"; do
echo "scriptmcr001 P:$p"
echo $p | grep " " > /dev/null
if [ $? -ne 0 ] ; then
command=${command}" "$p
else
command=${command}" "\"$p\"
fi
done
echo "scriptmcr001 - command:$command"
The last line shows the command I want built exactly as I require, however, I can't execute the command it as one of the passed paramaters has a space, so when I execute $command it ignores everything after the space.
Adding the following lines allows the script to work:
echo $command > runme.sh
chmod 777 runme.sh
runme.sh
But in the live environment the script will be run hundreds of times, so its not possible to write the output to a file.
Is there anyway to execute $command and not have the space issue. For example if it was possible to do something like:
echo $command | exec
Then that would be ideal, but this doesn't work.
Thanks in Advance
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО04-16-2009 04:02 AM
тАО04-16-2009 04:02 AM
Re: Passed Parameters and Spaces
# cmd=find
# p="/tmp -type f -mtime +7"
# cmd="${cmd} ${p}"
# ${cmd}
Notice that the word 'command' is a standard UNIX command. Hence to avoid ambiguity, I'd use something like 'cmd' as your variable name.
Regards!
...JRF...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО04-16-2009 04:35 AM
тАО04-16-2009 04:35 AM
Re: Passed Parameters and Spaces
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО04-16-2009 05:27 AM
тАО04-16-2009 05:27 AM
Re: Passed Parameters and Spaces
You need to quote your arguments if you want strings with embedded spaces to be counted as a single argument.
# cat ./showme
#!/usr/bin/sh
for p in "$@"; do
echo "${p}"
echo ${p}
done
Compare the output of:
# ./showme online report
# ./showme "online report"
# ./showme " online report"
Regards!
...JRF...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО04-16-2009 05:38 AM
тАО04-16-2009 05:38 AM
Re: Passed Parameters and Spaces
test1 xraf run srcu/test.p "online report"
In this case I am trying to send 4 parameters, yet when I receive the parameters I get 5 as it splits online and report as 2 parameters.
when I echo what I have in $cmd it is correct as it will build the string with any ammount of parameters. But when I execute $cmd, it tries to execute just the online part and ignores report.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО04-16-2009 07:03 AM
тАО04-16-2009 07:03 AM
SolutionSee if this helps you:
# cat ./passme
#!/usr/bin/sh
typeset -i n=1
set -A CMD
CMD[1]=$1
shift
for p in "$@"
do
((n=n+1))
echo ${p} | grep -c ' ' && CMD[${n}]=\"${p}\" || CMD[${n}]=${p}
done
echo ${CMD[*]}
eval ${CMD[*]}
# cat ./tester
#!/usr/bin/sh
echo "I see $# parameters"
for arg in "$@"
do
echo $arg
done
...and then:
# ./passme ./tester x y z "online report"
I see 4 parameters
x
y
z
online report
Regards!
...JRF...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО04-16-2009 07:08 AM
тАО04-16-2009 07:08 AM
Re: Passed Parameters and Spaces
Actually, there is no need _not_ to quote every argument (except the first, which is the object to execute). Hence, simplified:
# ./cat ./passme
#!/usr/bin/sh
typeset -i n=1
set -A CMD
CMD[1]=$1
shift
for p in "$@"
do
((n=n+1))
CMD[${n}]=\"${p}\"
done
echo ${CMD[*]}
eval ${CMD[*]}
Regards!
...JRF...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО04-17-2009 05:02 AM
тАО04-17-2009 05:02 AM
Re: Passed Parameters and Spaces
Thanks Again