本文介绍了BASH脚本中的简单mv命令的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我的脚本的目标:
- 查看目录($ Home/Music/TEST)及其子目录(它们是音乐文件)中的所有文件
- 找出每个文件属于哪种音乐流派
- 如果类型为 Heavy ,则将文件移动到另一个目录($ Home/Music/Output)
- look at all the files in a directory ($Home/Music/TEST) and its sub-directories (they are music files)
- find out what music genre each file belongs to
- if the genre is Heavy, then move the file to another directory ($Home/Music/Output)
这就是我所拥有的:
#!/bin/bash
cd Music/TEST
for files in *
do
if [ -f "$files" ];then
# use mminfo to get the track info
genre=`mminfo "$files"|grep genre|awk -F: '{print $2}'|sed 's/^ *//g'|sed 's/[^a-zA-Z0-9\ \-\_]//g'`
if [ $genre = Heavy ] ;then
mv "$files" "~/Music/Output/$files"
fi
fi
done
请告诉我如何编写mv命令.我尝试过的一切都失败了.我收到这样的错误:
Please tell me how to write the mv command. Everything I have tried has failed. I get errors like this:
请不要以为我写的是mminfo行-只是从旧的Google搜索中复制而来的.超越我了.
Please don't think I wrote that mminfo line - that's just copied from good old Google search. It's way beyond me.
推荐答案
您对mv
的第二个参数似乎是"~/Music/Output/$files"
Your second argument to mv
appears to be "~/Music/Output/$files"
如果~
旨在表示您的主目录,则应改用$HOME
,例如:
If the ~
is meant to signify your home directory, you should use $HOME
instead, like:
mv "$files" "$HOME/Music/Output/$files"
~
引用时不会扩展为$HOME
.
这篇关于BASH脚本中的简单mv命令的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!