1

I have a script part where I am checking if the file exist . I dont find where is my mistake because it jumps to else( file exists) and starts downloading that file. Part of code:

...
    if [ -f '$ins.img' ];
    then
        echo '$ins.img already exists'
    else
       wget http://$2/$ins/$ins.img
    fi
...
Dambre
  • 195
  • 2
  • 15

1 Answers1

0

It's because you're using single quotes in your if. Variables are not filled in inside single quotes, so it will check for a file literally named $ins.img, which obviously doesn't exist.

The solution is easy, use double quotes.

Bart van Heukelom
  • 43,244
  • 59
  • 186
  • 301