需要帮助建立bash文件。随函附上说明和示例

需要帮助建立bash文件。随函附上说明和示例,bash,automation,backup,Bash,Automation,Backup,我正在尝试构建一个(在我看来)复杂的bash文件,并希望了解如何编写它。我想知道怎么做,我不是要求你们帮我做:) 说明: #Step 1. #Copy Folder1 from InstallDrive:\(install.directory) to BackupDrive:\(backup.directory) ##Name Copied Folder1 to *Current Date*-Folder1 #Copy Folder2 from InstallDrive:\(install.di

我正在尝试构建一个(在我看来)复杂的bash文件,并希望了解如何编写它。我想知道怎么做,我不是要求你们帮我做:)

说明:

#Step 1.
#Copy Folder1 from InstallDrive:\(install.directory) to BackupDrive:\(backup.directory)
##Name Copied Folder1 to *Current Date*-Folder1
#Copy Folder2 from InstallDrive:\(install.directory) to BackupDrive:\(backup.directory)
##Name Copied Folder2 to *Current Date*-Folder2
#!!!Confirm Files Were Copied fully!!!
#Delete Folder1 from InstallDrive:\(install.directory)
#Delete Folder2 from InstallDrive:\(install.directory)
#Delete Folder3 from InstallDrive:\(install.directory)
#Step 2.
#Launch Program
##Login
##Let Run for x minutes
##Exit/Terminate Program
#Step 3.
#Copy most current *Current Date* Folder1 from BackupDrive:\(backup.directory)\ to InstallDrive:\(install.directory)
#Copy most current *Current Date* Folder2 from BackupDrive:\(backup.directory)\ to InstallDrive:\(install.directory)
任何帮助或指导都将不胜感激。
谢谢

太好了,现在你知道我肮脏的小秘密了。哈哈

这就是我到目前为止所做的:

#Step 1.
___________________________________________________________________________

#Copy Folder1 from InstallDrive:\(install.directory) to BackupDrive:\(backup.directory)
cp "C:\Program Files (x86)\Battle.net\Games\World of Warcraft\WTF\." "H:\wow.wtf.interface.backup.DND\WTF\." -R

##Name Copied Folder1 to *Current Date*-Folder1
#How do I make a dynamic date?
#How do I rename the file in the BackupDrive:\()BackupDirectory)?

#Copy Folder2 from InstallDrive:\(install.directory) to BackupDrive:\(backup.directory)
cp "C:\Program Files (x86)\Battle.net\Games\World of Warcraft\Interface\." "H:\wow.wtf.interface.backup.DND\Interface\." -R

##Name Copied Folder2 to *Current Date*-Folder2
#How do I make a dynamic date?
#How do I rename the file in the BackupDrive:\()BackupDirectory)?

#!!!Verify Files Were Copied fully!!!
#How do I do this?

#Delete Folder1 from InstallDrive:\(install.directory)
rm "C:\Program Files (x86)\Battle.net\Games\World of Warcraft\WTF\."

#Delete Folder2 from InstallDrive:\(install.directory)
rm "C:\Program Files (x86)\Battle.net\Games\World of Warcraft\Interface\."

#Delete Folder3 from InstallDrive:\(install.directory)
rm "C:\Program Files (x86)\Battle.net\Games\World of Warcraft\Cache\."

#Step 2.
___________________________________________________________________________

#Launch Program
start "Battle.Net" "C:\Program Files (x86)\Battle.net\Battle.net Launcher.exe"
start "World of Warcraft" "C:\Program Files (x86)\Battle.net\Games\World of Warcraft\Wow-64.exe"
##Login
*User Input*
##Let Run for x minutes
?
##Exit/Terminate Program
end "Battle.Net" "C:\Program Files (x86)\Battle.net\Battle.net Launcher.exe"
end "World of Warcraft" "C:\Program Files (x86)\Battle.net\Games\World of Warcraft\Wow-64.exe"

#Step 3.
___________________________________________________________________________

#Copy most current *Current Date* Folder1 from BackupDrive:\(backup.directory)\ to InstallDrive:\(install.directory)
cp "H:\wow.wtf.interface.backup.DND\WTF\." "C:\Program Files (x86)\Battle.net\Games\World of Warcraft\WTF\." -R

#See question at ##Name Copied Folder1 to *Current Date*-Folder1

#Copy most current *Current Date* Folder2 from BackupDrive:\(backup.directory)\ to InstallDrive:\(install.directory)
cp "H:\wow.wtf.interface.backup.DND\Interface\." "C:\Program Files (x86)\Battle.net\Games\World of Warcraft\Interface\." -R

#See question at ##Name Copied Folder2 to *Current Date*-Folder2

编辑:为什么我被否决了?

cp
=复制,
mv
(移动)=重命名,
rm
(删除)=删除。小心使用
rm
。另外,您的示例显示了典型的MS Windows路径信息,即InstDr:\instDir。对于bash的linux或Cygwin安装,请使用
/path/to/file
表示法。您对“让我们跑x分钟”的要求(相对而言)是一项高级要求。使用
cp、mv、rm获得一些结果,然后发布新问题。祝你好运。(我没有投反对票,但是)这不应该作为答案发布。关于S.O.的一个理论是,在初始Q下方添加一个标有“编辑”的部分,然后粘贴所有内容。另一个理论是提出另一个问题。我的理论是编辑您的原始问题,删除此答案中未包含的任何内容,将您的答案粘贴到您的问题中,保存,然后删除此“答案”。另外,请删除带有
#
字符的虚线或前缀,以便人们可以复制粘贴您的代码并运行它,而无需任何编辑。您可以使用
myDate=$(/bin/date+%Y-%m-%d)
将当前日期放入变量中。然后像
cp-pc:\..那样使用它。。。。h:\backupDirs\$myDate\moreDirs
。不确定“动态日期”是什么意思,它是作为cmd行上的参数传入的日期?或者您是否提示用户“您希望使用的日期”。。。您还需要使用
man-rm
man-cp
man-mv
来阅读每个命令的“man(ual)”页面。有一些选项可能适合您。最后,我建议发布一些小问题。这开始感觉像是免费咨询;-)。。。好啊祝你好运。很抱歉格式不正确。我对这里非常陌生,不熟悉像bash这样的简单“编程”(如果你想这样称呼它的话)。我最初是以编辑的形式发布的,但正如你所看到的,我再次更改了它,因为我不确定它的格式。另外,我来自Tom的硬件,那里需要长的帖子。再次感谢您的建议以及您的帮助和指导。您可以验证
cp
if cp src targ;然后回应“没有错误”;else echo“got RC=$?,表示错误”;fi或
cp src targ;rc=$;案例$rc在0)中回显“无错误”;*)echo“got RC=$RC;error!”;;esac`对于您剩下的问题,您最好将每个帖子的问题减少到1个,并表明您已经研究了S.O.好运网站上提供的内容。