A couple of days ago I came across a command
AWS_ACCESS_KEY=\"foo\" AWS_SECRET_KEY=\"bar\" aws list iam
I see that setting variables before
Shell is substituting your variable before running the command inside $()
. You can use &&
to make it work for you:
dname=$(date +%d_%m_%y) && mkdir ${dname} && cd ${dname}
or, of course:
dname=$(date +%d_%m_%y); mkdir ${dname} && cd ${dname}
However, dname
would be available to mkdir
if it were to grab the environment variable inside.
Let's say we have a script test.sh
that has a single statement echo $dname
inside. Then:
dname=$(date +%d_%m_%y) ./test.sh
would yield:
07_03_17
This is consistent with how your aws
command line worked.
Similar posts:
you are missing &&
before mkdir below is complete statement you desire:
dname=$(date +%d_%m_%y) && mkdir ${dname} && cd ${dname}
Also if its not necessary to declare dname
you can do:
mkdir $(date +%d_%m_%y) && cd ${dname}
both will give same answer