Reputation: 9
I am trying to set a variable in a UNIX Shell
script to a directory path plus file name with a date stamp. At the command prompt this produces the results. When I echo FILE_DATE
back to the screen in the script is produces The name $FILE_DATE
not the result. I thought this would be easy. I am apparently missing something easy.
My code:
FILE_DATE=echo ls -1 /opt/ftp/receive/SSA_SSI/SSA_Accounts_*.csv | grep -oP '[\d]+[\d]+[\d]+'
echo $FILE_DATE
Upvotes: 0
Views: 153
Reputation: 5339
$
character also missing.echo
command is not needed.Working script:
FILE_DATE=$(ls -1 /opt/ftp/receive/SSA_SSI/SSA_Accounts_*.csv | grep -oP '[\d]+[\d]+[\d]+')
echo ${FILE_DATE}
I have created a little presentation how it works:
>>> ls
7093966790966902785_n.jpg first_test.py second_test.py test.py
>>> MY_DATA=$(ls -1 *.py | grep "second")
>>> echo ${MY_DATA}
second_test.py
Upvotes: 1