gpt4 book ai didi

linux - 防止子字符串中的 Bash 分词

转载 作者:IT王子 更新时间:2023-10-29 00:23:56 26 4
gpt4 key购买 nike

如何防止 Bash 拆分子字符串中的单词?这是一个有点人为的例子来说明这个问题:

touch file1 'foo bar'
FILES="file1 'foo bar'"
ls -la $FILES

是否有可能通过 $FILES 中的 ls 命令将 'foo bar' 视为单个字符串,从而有效地导致与以下命令相同的行为?

ls -la file1 'foo bar'

最佳答案

使用数组:

files=( file1 'foo bar' )
ls -la "${files[@]}"

关于linux - 防止子字符串中的 Bash 分词,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17116593/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com