- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- Re: obtaining the variable inside the last arg ($#...
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-04-2004 09:31 PM
тАО04-04-2004 09:31 PM
easy one I hope, if I wanted to reference the last argument of the command line inside a script if the parameter list varied, then how do I reference it?
i.e. if the command line was :
script.sh a* c
where the script copies all args from $1 upwards (which represent files i.e. a1 a2 a3 a4, etc), excluding $#
.. and I wanted to reference c as the last parameter on the command line, then ideally I want to reference ${$#}, but I am struggling to escape it properly. My mind has gone blank again!!
hope this makes sense!
thanks in advance
John
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО04-04-2004 09:39 PM
тАО04-04-2004 09:39 PM
Re: obtaining the variable inside the last arg ($#)
perhaps something like this:
#/usr/bin/sh
NUMBER_1=$(( $# - 1))
shift $NUMBER_1
echo $1
regards,
John K.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО04-04-2004 09:48 PM
тАО04-04-2004 09:48 PM
Re: obtaining the variable inside the last arg ($#)
Another way could be:
for i in $*
do
last=$i
done
echo ${last}
Frank
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО04-04-2004 09:49 PM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО04-04-2004 09:50 PM
тАО04-04-2004 09:50 PM
Re: obtaining the variable inside the last arg ($#)
last="$#"
eval print \${$last}
exit 0