0

Good day! I have the following script which is supposed to rename and then send files in a folder on my Mac to an FTP server.

for f in "$@"
    do
        mv "$f" "${f%.mpeg}.mpg"
        curl -T "$f" ftp://1.2.3.4/Vol123456-01/MPEG/ --user me:secret
        mv "$f" "/Users/me/Sent Stuff"
    done

That works fine except for that first mv line. The script successfully renames the file, but then the following commands seem to no longer be able to find "$f". I am pretty new to bash scripting. Is there a way to refresh perhaps what "$f" means so that the curl and mv lines know what it is? Thanks in advance!

0

2 Answers 2

5

You have nailed the problem exactly. The first mv renames the file. The original name "$f" no longer exists. Try this:

for f in "$@"
do
    g="${f%.mpeg}.mpg"
    mv "$f" "$g"
    curl -T "$g" ftp://1.2.3.4/Vol123456-01/MPEG/ --user me:secret
    mv "$g" "/Users/me/Sent Stuff"
done
Sign up to request clarification or add additional context in comments.

1 Comment

That does it! Thanks!
3

You could store the new name in another variable and then use that when you want to reach the file.

newname="${f%.mpeg}.mpg"

and then use the "$newname" for getting the variable.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.