Shell script moving incoming files in to folder depending on prefix file name

Viewed 73

I am a total newbie and can’t pass a problem.

I have a process that transcode movie files to a folder. The files have a file name with two different prefixes.

I want to make all incoming NT_*.mp4 to be moved to one other predefined folder and all ET_*.mp4 to another predefined folder. They predefined with path and name.

Tried a simple if $fname=NT_*.mp4 then mv file to folder1 elif $fname=ET_*.mp4 mv that file to folder2. And that doesn’t work, it just move all files in the folder to folder1, so that is obviously wrong way.

So what do I need to do for checking each file for it prefix and then move them based on the prefix to predefined folders?

1 Answers

Spaces are important. It looks like you used something like

fname="wrong"
if [[ $fname=="right" ]]; then
  echo "Equal"
fi

You should add spaces around the equal sign:

fname="wrong"
if [[ $fname == "right" ]]; then
  echo "Equal"
fi
Related