Luke Livingstone
Luke Livingstone

Reputation: 129

Defining a variable before the variable is written

Currently, I have;

echo "Whats the year?"
read year
echo "Whats the Month you're running this for?"
read month

TARGET=`pwd`/"BLAH"$year$month"BLAH"
TARGET_888=`pwd`/"BLAH"$year$month"BLAH"

The output would be: pwd/BLAH201312BLAH for example. Is there any way I can use the variable, so define TARGET and TARGET_888 without using the echo's before this? I just want to make my code a lot neater and not have variables in the middle of my code.

Upvotes: 1

Views: 60

Answers (1)

anubhava
anubhava

Reputation: 785058

You can avoid echo by using read -p:

read -p "Whats the year?" year
read -p "Whats the Month you're running this for?" month

TARGET="$PWD/BLAH${year}${month}BLAH"
TARGET_888="$TAGET"

Upvotes: 1

Related Questions