Bash 脚本说找不到命令?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/19688963/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-18 08:27:12  来源:igfitidea点击:

Bash Script saying command not found?

bash

提问by LogicLooking

I am trying to write a simple backup script that does the following:

我正在尝试编写一个简单的备份脚本,它执行以下操作:

#!/bin/bash
#backupScript

mysqldump mysql -uxxxxx -pxxxxx Database1 Database2 | gzip > "MainWordPress.gz"

time_stamp = `date +%Y%m%d.%H%M`
file_name = 'backup-{$time_stamp}.tar.gz'
sources = 'DIR/ MainWordPress.gz'
tar -cvf file_name sources

rm MainWordPress.gz

cp file_name some/destination

But the issue is that it doesnt like:

但问题是它不喜欢:

./runBackup.sh: line 6: time_stamp: command not found
./runBackup.sh: line 7: file_name: command not found
./runBackup.sh: line 8: sources: command not found
tar: sources: Cannot stat: No such file or directory
tar: Exiting with failure status due to previous errors

and i'm deeply confused ...

我很困惑......

回答by opalenzuela

Remove the spaces around the equal sign:

删除等号周围的空格:

#!/bin/bash
#backupScript

mysqldump mysql -uxxxxx -pxxxxx Database1 Database2 | gzip > "MainWordPress.gz"

time_stamp=$(date +%Y%m%d.%H%M)
file_name="backup-${time_stamp}.tar.gz"
sources='DIR/MainWordPress.gz'
tar -cvf file_name sources

rm MainWordPress.gz

cp file_name some/destination

回答by Asenar

Remove the spaces between the variable and the =:

删除变量和 之间的空格=

#!/bin/bash
#backupScript

mysqldump mysql -uxxxxx -pxxxxx Database1 Database2 | gzip > "MainWordPress.gz"

time_stamp=`date +%Y%m%d.%H%M`
file_name='backup-{$time_stamp}.tar.gz'
sources='DIR/ MainWordPress.gz'
tar -cvf file_name sources

rm MainWordPress.gz

cp file_name some/destination