Concat Variable (date) and String in shell unix - bash

前端 未结 3 705
Happy的楠姐
Happy的楠姐 2021-01-03 11:42

I\'m trying to concat a var (date) and string to have a file with current date name.

My code.

days=\"$(date +\"%Y%m%d_%H%M\")\"
echo \"SKIP\" > ${         


        
相关标签:
3条回答
  • 2021-01-03 12:35

    I guess your vi will have made the entire file DOS-style and so there will be another carriage return at the end of the echo statement

    Try dos2unix or using an editor that allows you to change the line-ending style or

    sed -i "s/$( printf '\015' )//g" yourscript
    
    0 讨论(0)
  • 2021-01-03 12:42

    try to remove the redundant double quote in your first variable assignment.

    $ days=$(date +%Y%m%d_%H%M)
    $ echo $days #see what output will get?
    $ echo "SKIP" > ${days}_EMERGENCY.txt
    
    0 讨论(0)
  • 2021-01-03 12:48

    It works on my system (OS X) even with double quotes everywhere. For variation I used:

    $> days="$(date +'%Y%m%d_%H%M')"
    $> echo $days
    20160601_1051
    $> echo "SKIP" > ${days}_EMERGENCY.txt
    $> ll ${days}_EMERGENCY.txt
    -rw-r--r--  1 user  team  5 Jun  1 10:52 20160601_1051_EMERGENCY.txt
    
    0 讨论(0)
提交回复
热议问题