Assigne an expression to a variable

I hope this is not a duplicate thread, but i didn't find anything similar...

I had this script:

filename1=/swkgr/bin/risk/GF2KGR/arch/GF2KGR_M_
filename2=/swkgr/bin/risk/GF2KGR/arch/GF2KGR_D_
day='date +%m%d'
echo $filename1$day
echo $filename2$day

and i want this output:

/swkgr/bin/risk/GF2KGR/arch/GF2KGR_M_1015
/swkgr/bin/risk/GF2KGR/arch/GF2KGR_D_1015

(Path + timestamp)

But I have

/swkgr/bin/risk/GF2KGR/arch/GF2KGR_M_date +%m%
d
 
/swkgr/bin/risk/GF2KGR/arch/GF2KGR_D_date +%m%
d

(Path + instruction as string).

Where the error is? :confused:

not

day='date +%m%d'

but

day=$(date +%m%d)

It doesn't work, I had

syntax error at line 3: `day=$' unexpected

it works for me...

macbookeg:~ macbook$ day=$(date +%m%d);echo $day
1015

not space after $...

But for me it doesn't work, with or without space after of before $ (or any character, I tried anything).

Anyone has another solution?

try this

day=�date +%m%d�

The quotes are wrong. Try

day=`date +%m%d`

What shell are you using. The $() construct is for ksh/bash.

This was my first solution :frowning:

---------- Post updated at 11:28 AM ---------- Previous update was at 11:19 AM ----------

timestamp.sh: +%m%d\221: not found