在shell unix中Concat变量(日期)和字符串-bash [英] Concat Variable (date) and String in shell unix - bash

查看:181
本文介绍了在shell unix中Concat变量(日期)和字符串-bash的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试连接一个var(日期)和字符串,以使文件具有当前日期名称.

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

我的代码.

days="$(date +"%Y%m%d_%H%M")"
echo "SKIP" > ${days}_EMERGENCY.txt

但是当我运行时,我得到一个带有?的文件.在文件名中,如下所示:

but when I run, I get a file with a ? in file name, like this:

我做错什么了吗?

编辑

看着符号,?代表\ r-可能是因为我在记事本上书写,然后通过ftp上传.sh脚本吗?

Looking at symbol, ? stands for \r - could it be because I'm writing on notepad and then upload via ftp the .sh script?

编辑2

在本地计算机上尝试使用vi-现在情况也更糟.

Tried with vi on local machine - now it's also worse.

推荐答案

我想您的vi将使整个文件成为DOS风格,因此在echo语句的末尾还会有另一个回车符

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

尝试使用dos2unix或使用允许您更改行尾样式的编辑器或

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

sed -i "s/$( printf '\015' )//g" yourscript

这篇关于在shell unix中Concat变量(日期)和字符串-bash的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆