Script not working when called externally

Solution 1:

You are using a relative path, where your script is looking for the .mp4 files in the current directory i.e. the directory from where the script is being run, and finding that no such .mp4 file exists, then it looks for a literal *.mp4 file (assuming nullglob/failglob is not set, which is the default), and that file does not exist too, hence the error message *.mp4: No Such File or Directory.

You should use absolute path instead:

for i in /directory/*.mp4; do ...; done

Replace /directory/ with the actual directory path; if you want you can take the directory name as first argument too:

for i in "$1"/*.mp4; do ...; done

You can use absolute or relative path here, but again absolute path is always the safer option.

Now call the executable script in usual manner:

/path/to/script.sh /directory

From the script directory:

./script.sh /directory