用于命名设备上视频的 Shell 脚本

发布于 2024-08-26 22:30:16 字数 406 浏览 7 评论 0原文

我有一个 .sh 脚本,可以自动挂载插入的任何 USB 设备。我还需要它来查找插入的设备上的某个位置是否有视频,然后将它们写入 videos.txt 文件。这是我所拥有的,但它不起作用。我还需要它将挂载点放入videos.txt 文件中。 ${MOUNTPOINT}$count 是已安装设备的路径。

VIDEOS=ls ${MOUNTPOINT}$count/dcim/100Video | grep mp4
if [ "$VIDEOS" -ne "" ] ; then
    "${MOUNTPOINT}$count" > ${MOUNTPOINT}$count/videos.txt;
    "$VIDEOS" >> ${MOUNTPOINT}$count/videos.txt;
fi

我做错了什么?

I have a .sh script that automounts any usb device that is plugged in. I need it to also find if there are videos in a certain location on the device that is plugged in then write them to a videos.txt file. Here's what I have and its not working. Also I need it to put the mountpoint in the videos.txt file. ${MOUNTPOINT}$count is the path to the mounted device.

VIDEOS=ls ${MOUNTPOINT}$count/dcim/100Video | grep mp4
if [ "$VIDEOS" -ne "" ] ; then
    "${MOUNTPOINT}$count" > ${MOUNTPOINT}$count/videos.txt;
    "$VIDEOS" >> ${MOUNTPOINT}$count/videos.txt;
fi

What am I doing wrong?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

公布 2024-09-02 22:30:16
VIDEOS=$(ls ${MOUNTPOINT}$count/dcim/100Video | grep mp4)
if [ -n "$VIDEOS" ] ; then
    echo "${MOUNTPOINT}$count" > ${MOUNTPOINT}$count/videos.txt;
    echo "$VIDEOS" >> ${MOUNTPOINT}$count/videos.txt;
fi

使用 $() 执行过程并返回一个值。使用 -n 测试来检查非零字符串。 -ne 用于检查数字。 $VIDEOS 本身是一个字符串,而不是命令。为了将值放入文件中,您应该echo它。

VIDEOS=$(ls ${MOUNTPOINT}$count/dcim/100Video | grep mp4)
if [ -n "$VIDEOS" ] ; then
    echo "${MOUNTPOINT}$count" > ${MOUNTPOINT}$count/videos.txt;
    echo "$VIDEOS" >> ${MOUNTPOINT}$count/videos.txt;
fi

use $() to execute process and return a value. use -n test to check for non-zero strings. -ne is used to check for numbers. $VIDEOS by itself is a string, not a command. in order to put a value into a file, you should echo it.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文