0

I have hundreds of files that I import often, so the directories contain some spaces in addition to filenames with spaces. Each file has a 4 digit prefix (seq #) that I need to strip off. I am writing a script to do this each night but it does not seem to recognize. I have looked at many many ideas on this topic and non seem to work. So I wrote a tiny script to validate a files existence (see below)

 1 #!/bin/bash
 2 #PATH="junk/DirNo1/"
 3 PATH="junk/Dir\ No2/"
 4 #PATH="/home/roy/junk/DirNo1/"
 5 #PATH="/home/roy/junk/Dir\ No2/"
 6 
 7 FILE="8888\ rty.txt"
 8 CMB='"'$PATH$FILE'"'
 9 # CMB=${cmb// /\\ }
10 echo $CMB
11
12 if [[ -f "$CMB" ]]; then
13    echo "$FILE Exists"
14 fi
15
16 if test -f "$CMB"; then
17    echo "File exists.."
18 fi

As you can see I have tried just about everything, and the only thing that detects the presence of a file is having the PATH & FILE with NO spaces involved. I have tried double quotes around the path and/or filename, with and w/o escaped SPACES. These can't be that hard, so any ideas would be appreciated.

Nmath
  • 12,333
  • 3
    You shouldn't both escape and quote, and you certainly shouldn't use '"' to add literal quotation marks to the value. I would try PATH="junk/Dir No2" and FILE="8888 rty.txt" and CMB="$PATH/$FILE" then if [[ -f "$CMB" ]] ; then. – frabjous May 02 '22 at 00:07
  • Your suggestion worked! Learning the nuances of scripting is something I need to dive into – roy Yung May 02 '22 at 00:36
  • Want to say Thank you for you very prompt response too. – roy Yung May 02 '22 at 00:37

0 Answers0