0

Ohhhh, I've read a few pages and questions, but I just can't comprehend/fully understand it...

jdir0="$@"  # /home/tor/subbackup/teest2/jjj
mv  "$jdir0/subs/*.srt" /home/tor/subbackup/

mv: cannot stat '/home/tor/subbackup/teest2/jjj/*.srt': No such file or directory

Well, duh, yes, there is one test2.srt in there..

I've seen a few pages with tons of different solutions, and a as I have understood it, this should be translated to(the first move command):

mv /home/tor/subbackup/teest2/jjj/subs/test2.srt /home/tor/subbackup/

This one works fine in the terminal..

(The first move command), but I can't get it to work in the script.. what am I doing wrong?

3
  • If I understand you correctly: You should not quote a glob if you want it to be expanded. Change "$jdir0/subs/*.srt" to "$jdir0"/subs/*.srt. Also, please try to make a minimal example, apparently the first half of the script has nothing to do with the problem.
    – Quasímodo
    Aug 17 '20 at 19:59
  • understood, thx for the tip..
    – JoBe
    Aug 17 '20 at 20:40
  • I am confused. Are you doing the sarcasm right. You say "Well, duh, yes," then make a complete 180° turn. Aug 17 '20 at 20:59
2
jdir0="$@"

"$@" expands to all positional parameters / arguments to the script. When you assign it to a single variable, Bash concatenates them joined with spaces. You probably want just $1 here.

mv "$jdir0/subs/*.srt"

The variable expansion should indeed be quoted, since it prevents word splitting, and globbing if the variable contains something that looks like a glob. But here, you probably want the hard-coded glob to work, so it should not be quoted.

So leave the asterisk outside quotes, with e.g.

mv "$jdir0"/subs/*.srt

or e.g.

mv "$jdir0/subs/"*.srt

Both work the same, use which ever variant looks nicer to you.

1
  • .. that's the big difference from windows (pre win10) I was for windows, and there it was only one way to solve issues, with Linux there's so many solutions that I'm getting lightheaded.. thx for the info @ilkkachu
    – JoBe
    Aug 17 '20 at 20:43

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.