- c - 在位数组中找到第一个零
- linux - Unix 显示有关匹配两种模式之一的文件的信息
- 正则表达式替换多个文件
- linux - 隐藏来自 xtrace 的命令
我有一个 bash 脚本,我想处理空格。我知道这里有很多关于此的问题,但我无法解决我的问题。
根据我读过的内容,以下内容应该有效。中的空间../tool_profile/OS\Firmware/updater
正在转义。在脚本中,$2
变量在分配给 DEST
时用引号引起来。
如果我将此路径传递给 ls
,并在命令行中用引号括起来或使用转义空格,它就可以工作。
示例脚本命令:
./make_initramfs.sh initramfs_root/ ../tool_profile/OS\ Firmware/updater/ initramfs
脚本中 ls 的错误:
ls: cannot access ../tool_profile/OS Firmware/updater/: No such file or directory
make_initramfs.sh:
#!/bin/bash
if [ $# -ne 3 ]; then
echo "Usage: `basename $0` <root> <dest> <archive_name>"
exit 1
fi
ROOT=$1
DEST="$2"
NAME=$3
echo "[$DEST]"
# cd and hide output
cd $ROOT 2&>/dev/null
if [ $? -eq 1 ]; then
echo "invalid root: $ROOT"
exit 1
fi
ls "$2" # doesn't work
ls "$DEST" # doesn't work
# check for 'ls' errors
#if [ $? -eq 1 ]; then
# echo "invalid dest: $DEST"
# exit 1
#fi
#sudo find . | sudo cpio -H newc -o | gzip --best > "$DEST"/"$NAME"
感谢您对我做错了什么的任何线索! ^_^
最佳答案
好吧......当我提交这个时,我意识到我做错了什么。
在验证第二个之前,我传递了两个相对路径并更改为第一个。因此,一旦我更改了目录,第二个相对路径就不再有效。完成后我会发布更新的脚本。
编辑:我完成了脚本。见下文。Edit2:我根据大家的评论更新了这个。谢谢大家!
make_initramfs.sh:
#!/bin/bash
if (( $# != 2 )); then
echo "Usage: `basename $0` <root> <dest>"
exit 1
fi
root="$1"
archive="${2##*/}"
dest="$PWD/${2%/*}"
# cd and hide errors
cd "$root" &>/dev/null
if (( $? != 0 )); then
echo "invalid path: $root"
exit 1
fi
if [ ! -d "$dest" ]; then
echo "invalid path: $dest"
exit 1
fi
if [ "$archive" = "" ]; then
echo "no archive file specified"
exit 1
fi
if [ `whoami` != root ]; then
echo "please run this script as root or using sudo"
exit 1
fi
find . | cpio -H newc -o | gzip --best > "$dest"/"$archive"
关于linux - 巴什脚本 : handling paths with escaped spaces,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11458489/
我系统上的docker info命令输出如下: # docker info Containers: 0 Images: 0 Storage Driver: devicemapper ..... D
我如何捕获用户按下 ctrl + space + space? 我用这段代码成功测试了ctrl + space: RegisterHotKey(0, 1, MOD_CONTROL, VK_SPACE)
我有一个 Matlab 图,我想在论文中使用。此图包含多个 cdfplots。现在的问题是我不能使用标记,因为在情节中变得非常密集。如果我想让样本稀疏,我必须从 cdfplot 中删除一些样本,这将导
我正在尝试获取我将用于备份的服务器上所有数据库的列表。以下是我尝试打印数据库列表但出现错误的代码片段。如何解决?添加双方括号并不能解决问题。 我已经研究了一些类似的问题,但我无法弄清楚。 grep:字
我了解 new gen/old gen/perm gen 之间的区别,但我不知道“To Space”和“From Space”是什么。我看到我的“From Space”使用率达到 99.8%,而“To
我当前有一个返回时看起来像这样的字符串: //This is the url string // the-great-debate---toilet-paper-over-or-under-the-r
我太亲密了。我正在尝试编写用于Notepad++的正则表达式表达式,以用空格替换破折号,而忽略已经用前置/后置空格代替的破折号。我知道我可以用“foobarfoo”搜索/替换“-”,然后搜索“-”替换
我的 ANTLR 代码如下: LPARENTHESIS : ('('); RPARENTHESIS : (')'); fragment CHARACTER : ('a'..'z'|'0'..'9'|)
在过去的 6 个小时里,我一直在尝试在我的 webgl 应用程序中实现点击,但我找不到任何关于这个主题的足够清晰的内容。 到目前为止,我想出的是伪代码: screenSpace = mousePosi
如何使用正则表达式来测试空格或制表符,但不测试换行符? 我尝试了 \s,但我发现它也测试换行符。 我使用C# (.NET) 和 WPF ,但这应该不重要。 最佳答案 使用字符类:[\t] 关于rege
我想解析以下内容: name:name 名称以字母开头和结尾,并且可以包含字母和空格的任意组合。它们也可以是空白的。我的规则是: identifier = alnum (space* alnum)*;
有什么办法可以让 Eden 空间按比例大于 Tenured 空间吗?有 NewRatio 但它以相反的方式工作(Tenured 比 Eden 大几倍)。 我知道有 -XX:NewSize= 和 -XX
我正在编写一个程序,让人们输入他们的信息(姓名,年龄......)。对于姓名输入,我不希望他们留空,只允许字母和空格,但不能以空格开头。合适的正则表达式是什么?我尝试使用: ^[a-zA-Z\\s]*
好的,我正在制作一个程序,它也可以制作垂直线、水平线和对角线!我对我的一个没有任何意义的输出感到困惑。 所以我的伪代码是这样的: //enter a char //enter a number
当我使用 scp 从服务器复制文件时, 我错误地使用了命令 scp xxx@xxxx:xx.zip . 当我完成后,我发现该文件的名称是 .我无法解压 这是目录列表。 http://pfil
我需要一个 bat 文件来获取 Windows 系统中 C:\驱动器的总空间和可用空间(以 GB(千兆字节)为单位),并创建一个包含详细信息的文本文件。 注意:我不想使用任何外部实用程序。 最佳答案
作为预处理我的数据的一部分。我希望能够替换空格后跟数字,同时保留空格后跟一个字符。例如: Input String: '8.1.7 Sep 2000 Dec 2004 Dec 2006 Indefin
我正在编写一个 XPath 表达式,但我修复了一个奇怪的错误,但是以下两个 XPath 表达式之间有什么区别? "//td[starts-with(normalize-space()),'Posted
在 C 中,当读取文本文件时,是否有可能接受一个未知大小的整数值(假设它适合 int),因为它在数字之前和数字之后都有一个空格。例如。 363 865我想分别存储 363 和 865,因为它们有自己的
在 sys/ptrace.h 中,我看到类似这样的内容: @define PT_READ_I 1 /* read world in child's I space*/ @define PT_READ
我是一名优秀的程序员,十分优秀!