I am trying to chmod -R 644 /tmp/work/* in bash script, however I get following error:

#!/usr/bin/env bash
shopt -s extglob
set -eu

mkdir -p /tmp/work/
chmod -R 777 /tmp/work/
sftp -o StrictHostKeyChecking=accept-new user1@hostname1:/tmp/test* /tmp/work/
chmod -R 644 /tmp/work/*

chmod: cannot access '/tmp/work/*': No such file or directory

While I try to run the same command in shell with the same user, it runs successfully.

Seems like issue with shell is due to glob expansion? so I have set shopt -s extglob right before the chmod command in bash, but still getting the same error.

Any ideas what am I doing wrong?

  • 2
    Is test in user1@hostname1:test a file or a directory? The glob is just fine, and doesn't require an extglob at all ... I'm wondering whether the transfer actually worked ...
    – tink
    Sep 25 at 20:06
  • You are probably thinking about nullglob not extglob, but then chmod will complain about getting no files Sep 25 at 21:05
  • My bad, updated the typo test is actually multiple files and the transfer completed succesfuly as i can manually login view files and even do chmod, the only issue same doest work in bash Sep 25 at 21:36
  • 1
    After the sftp command, what does ls /tmp/work give you? Based on the error message, I'm expecting nothing at all Sep 26 at 11:04


You must log in to answer this question.

Browse other questions tagged .