The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
google unix.com




View Single Post in the UNIX and Linux Forums - Click on the Thread or Permalink to View Entire Thread -->
  #1 (permalink)  
Old 11-17-2008
chebarbudo's Avatar
chebarbudo chebarbudo is offline
Registered User
  
 

Join Date: Nov 2008
Location: various
Posts: 188
Question 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