0

I have the following script (bash under linux):

R=""
V=""
P=""

while getopts r:v:p: flag
do
    case "${flag}" in
        r) R=${OPTARG};;
        v) V=${OPTARG};;
        p) P=${OPTARG};;
    esac
done

But when i call it for example like this script.sh -r "some sring with spaces"

I get only "some" in the variable R.

Does someone see what i'm doing wrong here?

Tried different variants of quotation around nearly everything.

I want to give a para,meter -r with a path in it that may contain spaces.

  • Can't reproduce from the example. If I put `echo "$R"` at the end of the script I get `some string with spaces` as the output. My guess is that you're using `$R` somewhere else in your script and not quoting it. – tjm3772 Nov 20 '22 at 17:34
  • Not exactly a duplicate if your problem isn't echo-based, but this might help you: [I just assigned a variable, but echo $variable shows something else](https://stackoverflow.com/questions/29378566/i-just-assigned-a-variable-but-echo-variable-shows-something-else) – tjm3772 Nov 20 '22 at 17:35
  • Also, ["When should I double-quote a parameter expansion?"](https://stackoverflow.com/questions/55023461/when-should-i-double-quote-a-parameter-expansion) (short answer: almost always). – Gordon Davisson Nov 20 '22 at 18:11

0 Answers0