环顾四周,我没有看到我到底要找的东西。一些类似的东西,但由于某些原因,我到目前为止尝试的东西没有用。
我的主要目标:
这些是我试图遵循的来源:
Bash Shell Loop Over Set of Files
Bash loop through directory and rename every file
How to do something to every file in a directory using bash?
=============================================== ===================================
echo "Rename pictures. Path"
read path
for f in $path
do
eog $path
echo "new name"
read newname
mv $path $newname
cat $f
done
答案 0 :(得分:2)
您应该将脚本传递给参数,而不是尝试使其成为交互式。你也有很多引用问题。尝试这样的事情(未经测试):
#!/usr/bin/env bash
moveFile() {
local newName=
until [[ $newName ]]; do
printf '%s ' 'new name:'
read -er newName # -e implies Bash with readline
echo
done
mv -i "$1" "${1%/*}/${newName}"
}
if [[ ! -d $1 ]]; then
echo 'Must specify a path' >&2
exit 1
fi
for f in "$1"/*; do
eog "$f"
moveFile "$f"
done
答案 1 :(得分:0)
你可能想尝试这样的事情:
for f in $*; do
eog $f
echo "new name:"
read newname
mv $f $newname
done
如果您为脚本命名,例如rename.sh
,则可以致电
./rename.sh *gif
查看扩展名为“gif”的所有文件。
答案 2 :(得分:-2)
使用find
命令可以递归搜索指定目录中的图像文件。
echo -n "Rename pictures. Input image directory: "
read path
for f in `find $path -type f`
do
eog $f
echo -n "Enter new name: "
read newname
mv $f $newname
echo "Renamed $f to $newname."
done