- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- Shell script's command line parameter delimiter
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
02-02-2004 11:55 AM
02-02-2004 11:55 AM
I will have delimiter ":" instead of space (which is default) in the command line for e.g:
# testmail
/usr/sbin/sendmail -t << EOM
From:$1
To:$2
Subject:$3
$(/usr/bin/uuencode $4 $5)
EOM
In the above script,I want to pick up the delimiter ":" from the command line so as to pick up the positional parameter ($1,$2,$3..) values.
Appreciate if you can give some ideas.
Thanks much,
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-02-2004 12:17 PM
02-02-2004 12:17 PM
Re: Shell script's command line parameter delimiter
STRING=$1
FROM=`echo $STRING | awk -F: '{print $1}'`
TO=`echo $STRING | awk -F: '{print $2}'`
SUBJECT=`echo $STRING | awk -F: '{print $3}'`
FILE_ATTACH=`echo $STRING | awk -F: '{print $4}'`
NAME_ATTACH=`echo $STRING | awk -F: '{print $5}'`
this would preceed the rest of your script.
and instead of having "From:$1", you would have
From:${FROM}
etc.
It seemed to work when I used `echo $FROM`, etc.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-02-2004 12:48 PM
02-02-2004 12:48 PM
Re: Shell script's command line parameter delimiter
testmail "myname@mydomain.com:somebody@another.com:This is a test:/etc/issue"
testmail myname@mydomain.com:somebody@another.com:This\ is \a \test:/etc/issue
Otherwise, there will be $2 $3 etc. Be sure to test for $# to make sure there's only 1 parameter.
Bill Hassell, sysadmin
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-02-2004 01:04 PM
02-02-2004 01:04 PM
Re: Shell script's command line parameter delimiter
It might be what you want. Probably not.
I'm posting it anyway. Zero point me if its useless.
You'll have to use awk as shown above to do it with colons and spaces will still screw that up.
SEP
Owner of ISN Corporation
http://isnamerica.com
http://hpuxconsulting.com
Sponsor: http://hpux.ws
Twitter: http://twitter.com/hpuxlinux
Founder http://newdatacloud.com
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-02-2004 01:12 PM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-02-2004 07:26 PM
02-02-2004 07:26 PM
Re: Shell script's command line parameter delimiter
(echo $1 | awk '{printf "From:%s\nTo:%s\nSubject:%s\n",$1,$2,$3}'
lf=$(echo $1 | cut -d: -f4)
af=$(echo $1 | cut -d: -f5)
/usr/bin/uuencode "$lf" "$af"
) | sendmail -t
I would not recommend using awk for splitting the command line for each argument, as awk uses a lot of resources. The cut command is a lot smaller and does the trick quite right.
Mind the quotes for the uuencode arguments, because you could have spaces in the local or attachment filenames, due to the colon argument seperation.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-02-2004 07:29 PM
02-02-2004 07:29 PM
Re: Shell script's command line parameter delimiter
eval $(echo $1 | awk -F: '{printf "FROM='%s'\nTO='%s'\nSUBJECT='%s'\nLOCALFILE='%s'\nATTACHMENT='%s'\n",$1,$2,$3,$4,$5}')
Then the rest is simple and straight forward, since you have 5 environment variables containing the seperate parts.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-03-2004 04:42 AM
02-03-2004 04:42 AM
Re: Shell script's command line parameter delimiter
Best Regards,
Victor