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.
'"'
to add literal quotation marks to the value. I would tryPATH="junk/Dir No2"
andFILE="8888 rty.txt"
andCMB="$PATH/$FILE"
thenif [[ -f "$CMB" ]] ; then
. – frabjous May 02 '22 at 00:07