use several inputs as arguments in my script
Hi there,
It's pretty hard for me to explain my problem because I'm affraid I'm not using the correct vocabulary. So let me describe the situation. I wrote a script that has one argument. It works like this:
Code:
~$ cat /usr/local/bin/squote
echo "$@" | sed 's/'\''/'\''\\'\'\''/g; s/.*/'\''&'\''/g'
~$ squote It\'s great
'It'\''s great'
What do I need to do if I want my script to work in the following situation?
Code:
~$ echo It\'s great | squote
''
~$ cat file | squote
''
~$ squote < file
''
Thanks in advance
Santiago
Update:
Now I found that I can read from /dev/stdin. I wrote the following script:
Code:
~$ cat /usr/local/bin/squote
cat /dev/stdin | sed 's/'\''/'\''\\'\'\''/g; s/.*/'\''&'\''/g'
echo "$@" | sed 's/'\''/'\''\\'\'\''/g; s/.*/'\''&'\''/g'
~$ echo It\'s great | squote
'It'\''s great'
''
~$ squote It\'s great
# I need to press Ctrl+D
'It'\''s great'
How can I know from which input the argument is coming?
Last edited by chebarbudo; 11-17-2008 at 10:15 PM..
Reason: found part of the answer
|