- android - 多次调用 OnPrimaryClipChangedListener
- android - 无法更新 RecyclerView 中的 TextView 字段
- android.database.CursorIndexOutOfBoundsException : Index 0 requested, 光标大小为 0
- android - 使用 AppCompat 时,我们是否需要明确指定其 UI 组件(Spinner、EditText)颜色
我必须为以下问题编写 Linux 脚本
Write a script that renames files based on the file extension. The script should prompt the user for a file extension.
Next, it should ask the user what prefix to prepend to the file name(s). By default the prefix should be the current date in YYYYMMDD format.
So, if the user simply presses enter the date will be used. Otherwise, whatever the user entered will be used as the prefix.
Next, it should display the original file name and the new name of the file. Finally, it should rename the file.
我在下面写了 shell 脚本及其抛出错误。对我来说,脚本看起来完全没问题。虽然我能够编写替代脚本,但有人可以建议此脚本中错误的原因和解决方案。
脚本:
#!/bin/bash
read -p "Please enter a file extension : " EXT
for f in *.${EXT}
do
read -p "Please enter a file prefix (Press ENTER to prefix current Date) :" PREFIX
if [ -z "PREFIX" ]
then
new = "$(date +"%Y-%M-%d")-$(basename ${f})"
mv $f $new
echo "$f renamed to $new"
else
new = "${PREFIX}-${f}"
mv $f $new
echo "$f renamed to $new"
fi
done
错误:
./new.sh: line 13: new: command not found
BusyBox v1.24.2 (2017-05-25 17:33:59 CEST) multi-call binary.
Usage: mv [-fin] SOURCE DEST
or: mv [-fin] SOURCE... DIRECTORY
Rename SOURCE to DEST, or move SOURCE(s) to DIRECTORY
-f Don't prompt before overwriting
-i Interactive, prompt before overwrite
-n Don't overwrite an existing file
*.png renamed to
[root@localhost ~]#
[root@localhost ~]#
最佳答案
空格会在分配期间破坏您的脚本
#new = "$(date +"%Y-%M-%d")-$(basename ${f})"
new="$(date +"%Y-%M-%d")-$(basename ${f})"
还有
#new = "${PREFIX}-${f}"
new="${PREFIX}-${f}"
shellcheck是基本 shell 检查的优秀工具
关于Linux 脚本抛出错误,虽然它看起来完全没问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52964037/
请看下面我的构造函数,我正在从字符串创建一个分数: public Fraction(String str) { if(str.isEmpty()) {
当我向不可变 map 添加对象时,我注意到了这一点。 如果我添加一个对象,例如: Map model = ImmutableMap.of( "post", post
偶尔在我的网站上,我注意到无法加载外部文件。如果我重命名它并指向新名称,它就可以正常工作。旧名称不再有效。 通常这发生在图像上,但今天它发生在 css 文件上。它会自然而然地发生,而且是不可预测的。当
好的,我以 root 身份登录到 MySQL 命令行客户端。然后我以 root 身份使用 MySQLdb 模块打开或运行一个 python 应用程序。当我使用 python (IDLE) 检查结果时,
这个问题源于看Rasmus Lerdorf's talk from Drupalcon .顺便说一下,这个问题和他的演讲与 Drupal 没有任何关系……只是在他们的 session 上提出的。我自己
在使用 AJAX 提交创建表单后,我感到非常自豪,我在 IE8 中测试它并得到“消息:‘数量’未定义”。我读到这可能与早期版本的 IE 使用 ActiveX 进行 AJAX 请求有关,但我对 JS 很
对于我的一个项目,我必须对构造函数进行动态调用。但由于这是 Java 7,我使用 java.lang.invoke 而不是“经典”反射 API。 代码: @ParametersAreNonnullBy
基本上,我收到原始时间戳,我需要将它们格式化为 HH:MM:SS 格式。 最佳答案 这是一个提供 UTC 日期灵活格式的函数。它接受类似于 Java 的 SimpleDateFormat 的格式字符串
差不多两周后...我放弃了!!! 我实现了从图库和相机上传图片... startActivityForResult... ok! EXTERNAL_CONTENT_URI... ok! ACTIO
我有六张尺寸为 350x400 (WxH) 的 .jpg 图像。 我想将它们变成质量好(但不太重)且尺寸相同的 avi 文件 我正在做: /var/www/html/folder/ffmpeg/ffm
在我的应用程序中,我正在播放一些电影。我已经检查了电影的信息,它们似乎在 MPMoviePlayerController 应该能够处理的范围内(比特率等) 它们通过 URL 进行流式传输,并且只能在
program UInt32ToVariant; uses Vcl.Dialogs, System.SysUtils, System.Variants; var ui32Val: Cardin
无法弄清楚我的 Electron 项目出了什么问题。以 electron . 开头一个 native 模块(pkcs11js)将失败。见图片: 但运行 npm run dist将构建安装程序就好了,并
我正在使用 boost 文件系统获取当前目录的路径,然后检查该目录是否存在。 is_directory()没问题,但是 exists()在同一条路上失败了,我错过了什么吗? 示例代码(boost 1.
此使用 JFrames 的测试代码按预期工作(将在 10 秒后关闭)。 // **** Imports **** import java.awt.*; import javax.swing.JFram
我有一个相当复杂的 LINQ 查询,它通常很慢,它创建了一个 System.Data.SqlClient.SqlException : "等待操作超时"。 但是,当我记录生成的 SQL(通过将 Tex
这个问题在这里已经有了答案: When does JS interpret {} as an empty block instead of an empty object? (2 个答案) 关闭 5
我正在尝试实现一个哈希表。我收到上述错误,但 AFAIK 我已经正确声明了我所有的结构/typedef。 (我还在学C,sorry)错误发生在我的 while 循环中的 test.c 中,我在其中放置
例如 sprintf(pos,"%f ",cl.snap.ps.origin[0]); //don't start with strcat sprintf(tmp,"%f ",cl.snap.ps.o
好的,这是程序,绝对正确 #include using namespace std; template void Swap(T &a , T &b); int main(){ int i
我是一名优秀的程序员,十分优秀!