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:
~$ 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?
~$ 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:
~$ 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?