I have a shell script I'd like to run, but it fails in accessing the external drive path with spaces. I'm not sure which escaping characters to use here. I've tried hard escape \ and quotes. The error I get is:
ls: /Volumes/G-DRIVE: No such file or directory
ls: R-Series/Sentinel-1/path_82_frame_648_example/*.zip: No such file or directory
ls: SSD: No such file or directory
ls: mobile: No such file or directory
The original script is:
#!/bin/sh
Path_S1=/Volumes/'G-DRIVE mobile SSD R-Series'/Sentinel-1/path_82_frame_648_example/
Path_sub=/Volumes/'G-DRIVE mobile SSD R-Series'/Sentinel-1/path_82_frame_648_sub/
oldEnd=.zip
newEnd=subset_Orb
for i in $(ls -d -l $Path_S1$S1*.zip)
do
n=${i%.*}
n=${i%T*}
n=${n#"${n%_*}_"}
date
/Applications/snap/bin/gpt /Users/brbell01/Documents/SNAP/subset_and_update_orbits_gpt.xml -Pinput1=$i -Poutput1="$Path_sub$n$newEnd"
date
done
sh(Bourne-shell) is usally notbash(Bourne-again shell).n=...statements. Show a typical filename, and the substring you're trying to extract from it.ls -d -l "${Path_S1}"$S1*.zip, and if$S($S1??) can contain white space:ls -d -l "${Path_S1}${S}"1*.zip