我只是好奇,因为对于普通的用户脚本,我必须检查相应的文件是否可以被用户读取,是否可以写成这样(只是读取操作的一个片段):
if ! [ -r "$1" ]; then
dump_args "$@"
print_error__exit "! [ -r $1 ]" "The file is not readable by you!"
fi
我的问题是:在整个Linux (如果必须是,比如说Mint或Debian)系统上,是否有任何文件不可读或不能用root写?
我相信,总的来说,根可以做任何事情,但是一切都有限度,对吧
我有一个模板文件(template.txt):
Hello, $x
Hello, $y
我有一个脚本文件(script.sh):
#!/bin/bash
$x=linux
$y=unix
# I want to include template.txt as a here-doc
如何将template.txt包含为here-doc of script.sh。
因此,当我运行script.sh时,输出应该是:
Hello, linux
Hello, unix
编辑:
我认为replace对我的工作来说是个很好的命令:
$ cat template.txt | replace '$x&
我有一个由windows系统生成的CSV文件。然后将该文件移动到linux。linux环境是NAME="Red Hat Enterprise Linux Server".VERSION="7.3 (Maipo)".ID="rhel“。
当我使用vi编辑器时,所有的字符都是可见的。例如,给出了一行:"Sarah--bitte nicht löschen“。
但是当我猫文件时,我得到类似于"Sarah--bitte nicht l▒schen“之类的东西。
此文件由数据存储应用程序使用,并且此unicode字符为"?“在数据存储中。由
我已经编写了shell脚本,它从输入文件中读取命令并执行命令。我有这样的命令:
cat linux_unit_test_commands | grep "dmesg"
在输入文件中。在执行shell脚本时,我收到下面的错误消息:
cat: |: No such file or directory
cat: grep: No such file or directory
cat: "dmesg": No such file or directory
剧本:
#!/bin/bash
while read line
do
output=`$line
名为animals的原始文件如下所示:
dog
cat
dolphin
cat
这个命令通过将sed '/dog/i\ Linux Scripting' animals放在Linux Scripting之前来工作,我得到了以下内容:
Linux Scripting
dog
cat
dolphin
cat
然而,如果我做了动物头之后,文件是不变的。
$ head animals
dog
cat
dolphin
cat
如何以覆盖现有文件的方式执行此操作?
注意:用于多个文件,我希望animals与*.txt保持一致