- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- Re: Issue with shell scripts environment variable
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
тАО03-02-2011 05:59 AM
тАО03-02-2011 05:59 AM
I'm writing a script in which the command I need to run might change depending on certain conditions. Therefore I'm building the command line and saving this command in an environment variable, which I run at a later stage.
Something like RUN_CMD="ls -l | grep -v -E "total|SERVER" | cut -d' ' -f1|sort -r"
The command line is just an example, but I have to combine more than one commands using a pipe.
When I try to run this constructed command line, I get error messages like -v no such file etc.
|grep: unknown host name.
-v: unknown host name.
-E: unknown host name.
"HOST_NAME|host1|host2"|: unknown host name.
cut: unknown host name.
-d': unknown host name.
': unknown host name.
-f1|sort: unknown host name.
-r: unknown host name.
Thanks in advance for your suggetions.
Regards
Kaushik
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО03-02-2011 06:08 AM
- Tags:
- eval
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО03-02-2011 07:42 AM
тАО03-02-2011 07:42 AM
Re: Issue with shell scripts environment variable
eval ${RUN{COMMAD}
Kaushik
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО03-02-2011 08:56 PM
тАО03-02-2011 08:56 PM
Re: Issue with shell scripts environment variable
I assume this was an exercise for the user?
This works:
RUN_CMD="ls -l | grep -v -E 'total|SERVER' | cut -d' ' -f1 | sort -r"
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО03-03-2011 01:56 AM
тАО03-03-2011 01:56 AM
Re: Issue with shell scripts environment variable
This is what I have done in my script.
RUN_CMD="ls -l ${CLUSTERS} | ${PATH_GREP} -v -E \"HOST_NAME | ${SERVER_MANAGER}\" | cut -d' ' -f1 | sort -r"
.
.
.
.
eval $RUN_CMD > ${TMP_FILE}
This worked.
JRF's suggestion to -
use either double or single quotes *only* to surround the whole command:
also worked.
#RUN_CMD="ls -l server02/ | grep -v -E 'total|SERVER' | cut -d' ' -f1|sort -r"
#eval $RUN_CMD
Once again thank you all for your suggestions.
Thanks and Regards
K