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:

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

You can test, if the script was called with an argument:

[[ -z "$@" ]] && printf "No input\n" || printf "Input: %q\n" "$@"

Which means: if the length of the arguments ( $@) is zero (-z) then print "No input" else print the string in escaped form. I don't not, what you want to achieve, but if you try to escape strings, check the %q option of printf.

If you call the testscript this way:

testscript "h's m"

it will give you:

Input: h\'s\ m

Thx Christoph,
Although printf is a much better function for my script, you don't answer at all to my problem. What I need is a way to make the script work in the following situation:

~# cat /usr/local/bin/squote
[[ -z "$@" ]] && printf "No input\n" || printf "Input: %q\n" "$@"
~# echo "h's m" | squote
No input