linux - How to get this bash script to work if the variable "fileName" contains space? -


#!/bin/bash -x  echo "enter file name: " read filename filename=`pwd`"/$filename" if [ -f $filename ];     echo "file present" fi 

even if change value of filename adding quotes @ starting , end.. script still doesnt work.

wrapping in double-quotes works me:

#!/bin/bash -x  echo "enter file name: " read filename filename=`pwd`"/$filename" if [ -f "$filename" ];         echo "file present" fi 

i believe take care of special characters, including quotes themselves.


Comments

Popular posts from this blog

ios - MKAnnotationView layer is not of expected type: MKLayer -

ZeroMQ on Windows, with Qt Creator -

unity3d - Unity SceneManager.LoadScene quits application -