0

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
7
  • 2
    Please paste your script at shellcheck.net and try to implement the recommendations made there. Commented Nov 4, 2021 at 20:17
  • Btw.: sh (Bourne-shell) is usally not bash (Bourne-again shell). Commented Nov 4, 2021 at 20:18
  • I'm not sure what you're trying to accomplish with the series of n=... statements. Show a typical filename, and the substring you're trying to extract from it. Commented Nov 4, 2021 at 20:30
  • BTW, parameter expansions cannot be nested Commented Nov 4, 2021 at 20:31
  • addressing just the error message, wrap variable reference in double quotes, eg: ls -d -l "${Path_S1}"$S1*.zip, and if $S ($S1 ??) can contain white space: ls -d -l "${Path_S1}${S}"1*.zip Commented Nov 4, 2021 at 20:33

1 Answer 1

1

The main problems:

A bit of a rewrite for readability:

PATH="/Applications/snap/bin:$PATH"

root='/Volumes/G-DRIVE mobile SSD R-Series/Sentinel-1'
Path_S1="$root/path_82_frame_648_example"
Path_sub="$root/path_82_frame_648_sub"

data=/Users/brbell01/Documents/SNAP/subset_and_update_orbits_gpt.xml
oldEnd=.zip
newEnd=subset_Orb

for zip in "$Path_S1"/*"$oldEnd"    # don't quote the wildcard
do
    # do something here to extract $n

    date
    gpt "$data" -Pinput1="$zip" -Poutput1="$Path_sub/${n}$newEnd"
    date
done
Sign up to request clarification or add additional context in comments.

2 Comments

Thanks Glenn Jackman for your answer. Are double quotes and single quotes functionally equivalent? I'm still getting an error: Error: [NodeId: Read] Specified 'file' [input1] does not exist
They are not. See 3.1.2 Quoting in the manual.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.