- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - Linux
- >
- Modify ksh script to accept input from file
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
тАО11-18-2005 03:15 AM
тАО11-18-2005 03:15 AM
Modify ksh script to accept input from file
...script [file]
Inside the sciprt I check some stuff and go:
...INFILE=$1
and thenn operate on $INFILE.
Now I find I want to pipe the output of another script (my 1st script) into my 2nd script.
..first_script.ksh | second_script.ksh
so that my 2nd script has no argument now.
How do I modify the 2nd script to take standard input if no file is specified; or read a file if a file is specified?
I tried:
...INFILE=&0
but that didn't do it...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО11-18-2005 03:32 AM
тАО11-18-2005 03:32 AM
Re: Modify ksh script to accept input from file
Do something like this:
[ -z "${1}" ] && exec < /dev/tty || exec < ${1}
...instead of :
INFILE=$1
Regards!
...JRF...
- Tags:
- variable
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО11-18-2005 04:14 AM
тАО11-18-2005 04:14 AM
Re: Modify ksh script to accept input from file
Pipe stdin with xargs w/o changing code in the 2nd script to get the result...
# first_script.ksh | xargs second_script.ksh
...this way you don't need to change the definition of INFILE=$1.
cheers!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО11-18-2005 05:59 AM
тАО11-18-2005 05:59 AM
Re: Modify ksh script to accept input from file
try this in 2nd script:
#!/usr/bin/sh
if [ -t 0 ]
then
echo I am not piped to, read parameter
INFILE=$1
else
while read line
do
echo processing std in from $line
done
fi
~
regards,
John K
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО11-21-2005 02:24 AM
тАО11-21-2005 02:24 AM
Re: Modify ksh script to accept input from file
You may only have to make very small changes to the script, you may have to do a major renovation, epically if you want to keep both capabilities.
Another option, though somewhat less efficient, is to give your 2nd script a flag that takes piped input and just writes it to a temp file and then uses that tmp file name as the parameter for the input file. I know that├в s kind of dirty and you have to remember to clean up the file at the end too but it requires less script renovation and the script works basically the same way for either piped or file name data.
Howard
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО12-05-2005 09:33 AM
тАО12-05-2005 09:33 AM
Re: Modify ksh script to accept input from file
He wrote:
[ -z "${1}" ] && exec
The correct answer was:
[ -z "${1}" ] && exec<&0 || exec<${1}
i.e. - take input from "stdin" if $1 zero, or from $1 if $1 is non-zero.
Points not working - I'll do them tomorrow.