Add Comment
|
Related Links
|
TrackBack
Executing a String from the UNIX Shell ScriptSometimes, in your shell script, you'd want to read in a command--from a file, an user input, etc.--and executing it. It's easy if the command is a simple command that doesn't involve pipe and redirection. But when you involve pipe and redirection, the execution fails. Take the following example script for example: #!/bin/sh This is a simple shell script that want to send the /etc/hosts.deny file through the grep function. It's stored in the cmd variable to be executed at a later time. The following is the output of this script: ALL: ALL When executed, cat sends the /etc/hosts.deny file to the stdout and report that "|", "grep", and "waldo" are not found. cat thinks those arguments are file name specifications. One way to deal with this problem is to write the command string into a temporary executable script and executing it. GetTempPathName.ksh posted elsewhere on this site is useful for this purpose. The following shell script demonstrates this practical example: #!/bin/sh Chieh Cheng
Add Comment
|
Related Links
|
TrackBack
Did your message disappear? Read the Forums FAQ. Add CommentSpam Control | * indicates required field TrackBackTrackBack only accepted from WebSite-X Suite web sites. Do not submit TrackBacks from other sites. Send Ping | TrackBack URL | Spam Control No TrackBacks yet. TrackBack can be used to link this thread to your weblog, or link your weblog to this thread. In addition, TrackBack can be used as a form of remote commenting. Rather than posting the comment directly on this thread, you can posts it on your own weblog. Then have your weblog sends a TrackBack ping to the TrackBack URL, so that your post would show up here. Messages, files, and images copyright by respective owners. |
Products
|
Services
24 Users Online
|
Copyright © 1996 - 2024. All Rights Reserved. |