0
set -x 
for f in ~/1/2/*/*_1.txt; do
subdir="${f%/*}"
pushd "$subdir" &>/dev/null
file="${f##*/}"

expTool INPUT1= "${f##*/}" INPUT2= "${f%_1.txt}_2.txt OUTPUT1= "${f%_1.txt}_3.txt" OUTPUT2= "${f%_2.txt}_4.txt"
done

expTool error: [Errno 2] No such file or directory: '*_1.txt'

I have subtracted the quotations, but it was a no go.

EDIT: With set -x

+for f in '/User/admin/1/2/*/*_1.txt'
+subdir='/User/admin/1/2/*'
+pushd '/User/admin/1/2/*'
+file='*_1.txt'
+expTool INPUT= '*_1.txt' OUTPUT= '${f%_1.txt}_2.txt'

So it looks like the '*' syntax is not being registered as a wildcard(?). I am using Mac OSX 10.8.6.

2
  • Comments are not for extended discussion; this conversation has been moved to chat. Commented Feb 5, 2016 at 14:01
  • OS/X comes with zsh. You don't have to use bash there. Commented Feb 5, 2016 at 21:45

2 Answers 2

1

Either you ran set -f earlier in the script, which disables wildcard expansion, or there are no matching files. If there are no matching files, the pattern is left unchanged, so the for loop runs on one element which is the unchanged pattern. In bash, you can use shopt -s nullglob to make non-matching patterns instead expand to the empty list.

0

i am not sure that i understand your code,

for f in ~/1/2/*/*_1.txt; do
  fdn="${f%/*}"
  fbn1="${f##*/}"
  fbn2="${fbn1//_1/_2}"
  fbn3="${fbn1//_1/_3}"
  fbn4="${fbn1//_1/_4}"
  expTool INPUT1= "$fdn/$fbn1" INPUT2= "$fdn/$fbn2" OUTPUT1= "$fdn/$fbn3" OUTPUT2= "$fdn/$fbn4"
done

if i am of toppic please let me know , i delete my answer!

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.