Henry David
Henry David

Reputation: 441

Shell function, do action with one arg

I'm trying to do something simple, such as mkdir based on a given argument.

#!/bin/bash

make_picNum() {
    arg1 = $1
    echo "Making picture folder $arg1..."
    echo "mkdir picNum_$arg1"
    echo "Created album folder"
}

I'm assuming I have some basic syntax flaws. The current output/action of running this with any given number as an argument is nada.

Upvotes: 0

Views: 145

Answers (2)

doubleDown
doubleDown

Reputation: 8408

I'm creating this in a .sh, then chmod +x file.sh and ./file.sh args

If that's the case, you don't really need that function inside the script, i.e. you can just have this

#!/bin/bash

echo "Making picture folder $1..."
mkdir "picNum_$1"
echo "Created album folder"

Upvotes: 0

aecolley
aecolley

Reputation: 2011

Your script defines a function called make_picNum but it never calls that function. Try adding this at the end:

make_picNum "$1"

Also, you need to remove the spaces around =.

Upvotes: 2

Related Questions