Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/mysql/65.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
转储目录Shell脚本_Shell - Fatal编程技术网

转储目录Shell脚本

转储目录Shell脚本,shell,Shell,我不熟悉shell脚本 我正在尝试使用以下方法转储日志文件中的目录: echo -n "Enter Starting Point : "; read SRC echo $SRC find $SRC -type d >log.txt 应该保存在log.txt中的上述代码的输出为空。如果我编写以下代码: echo -n "Enter Starting Point : "; read SRC echo $SRC find ~ -type d >log.txt 它很好用。 这段代码有什么

我不熟悉shell脚本

我正在尝试使用以下方法转储日志文件中的目录:

echo -n "Enter Starting Point : "; read SRC
echo $SRC
find $SRC -type d >log.txt
应该保存在log.txt中的上述代码的输出为空。如果我编写以下代码:

echo -n "Enter Starting Point : "; read SRC
echo $SRC
find ~ -type d >log.txt
它很好用。
这段代码有什么问题?

~是您的home dir,所以您将your home dir转储到log.txt,第一个是输入dir转储到log.txt。

我通过将输入作为/home而不是“~”(不带引号)解决了我的问题。

此脚本无法处理各种输入。例如,如果要搜索名为
foo-bar
(带空格)的目录,则
find
命令将尝试查找可能不存在的
foo
bar


而且,这不是小事。如果要将主目录传递给脚本,最好使用
$home

您看到了吗:
echo
命令在
$SRC
中说了什么?它是一个目录吗?解决的问题使用了第一个代码而不是“~”我把输入作为“/home”,它工作了:)我知道它们是用来做什么的,但问题是如果我把“~”(没有引号)作为输入,它就不工作了。是的,作为输入,它只是一个字符,但它是sh中的当前目录。不,
~
是当前用户的主目录
$PWD
是当前目录。