linux - 使用 shell 脚本压缩字典

标签 linux shell unix ubuntu compression

我想用这种格式压缩字典:2011.16.03_root_backup.tar.gz(日期后跟用户名)。但是我的 shell 脚本代码不起作用,并且缺少一些代码。你能帮帮我吗?

#!/bin/sh
date=$(date +"%y-%d-%m")
user=$(whoami)
target=(i want to get this as an argument)
tar -cvf ./$date_$user_backup.tar.gz $target 

最佳答案

为您的 tar 命令尝试这一行:

tar -czvf ./${date}_${user}_backup.tar.gz ${target}

问题是 $date 或 $user 之后的 _ 不被 shell 视为单词分隔符,这就是为什么这里需要 ${var} 形式。

关于linux - 使用 shell 脚本压缩字典,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5330428/

相关文章:

linux - Bash/expect脚本控制执行

python - 如何在 linux 上将日文平假名字符输入到 python 2.6 shell?

linux - 使用模式将带有数字的字符串加 1

database - 考虑夏令时将(日期)类型的oracle历史数据转换为unix时间戳

linux - Raspberry pi sudo apt-get install apache2 给出错误(404 Not Found)

linux - 在 IDE 或系统范围内安装框架?

linux - 如何在shell脚本中收集变量中的多行

bash - 如何使用 getopt(s) 作为在 bash 中传递参数的技术

linux - linux 上需要 docker-machine 吗?

linux - ccmake。与 ccmake [路径]