security problems in bash script



Hello everyone,

I have this simple bash script that reads from standard input and executes
some work depending on the input that it has read. The input lines are
meant to be in the form of a command followed by an argument.

#!/bin/bash

read input

#these two lines divide input in a first word and the rest; are they safe?
command=`echo ${input%% *}`
rest=`echo ${input#* }`

case $command in

print)
echo $rest
;;

*)
echo "wrong command"
;;

esac


Is is possible for the user to provide something to the standard input and
make this script do something different from what it was meant?

I often see that the argument of case statement is enclosed in a pair of
inverted commas ( case "$command" in ... ); what is the purpose of the
inverted commas?


Thanks
.



Relevant Pages

  • Re: Yet another "stop the bash quoting" post
    ... |> Output from running the file1.sh command is: ... |> the argument doesn't contain those single quotes; ... | By using set -x in the bash script and running /command/ without the ...
    (comp.os.linux.misc)
  • Re: Yet another "stop the bash quoting" post
    ... |> Output from running the file1.sh command is: ... |> the argument doesn't contain those single quotes; ... | By using set -x in the bash script and running /command/ without the ...
    (comp.unix.shell)
  • security vulnerabilities in bash script
    ... I have this simple bash script that reads from standard input and executes ... meant to be in the form of a command followed by an argument. ... echo "wrong command" ...
    (comp.os.linux.security)
  • RE: read line from terminal
    ... You can store the result of the particular command to a variable in ur bash script. ... echo $value ...
    (RedHat)
  • Re: One-Liner Help with -e + ksh heredoc
    ... they supply the given text via standard input. ... the text is indeed presented to stdin rather than on the command line: ... to echo. ...
    (comp.unix.shell)