【发布时间】:2023-03-17 11:18:01
【问题描述】:
谁能向我解释为什么这不起作用?
ls ~\ 确实表明 cheatsheet 在主目录中
1 #! /bin/bash
2 let i=0
3 cheatsheet="~/cheatsheet"
4 until [ $i -eq $# ]
5 do
6 grep -e $"$i" -e "^\s" $cheatsheet
7 i=$(expr $i + 1 )
8 done
9 if [ -z $1 ]
10 then
11 grep -e "^\w" $cheatsheet
12 fi
【问题讨论】:
-
~在扩展变量时不被处理。 -
另外,您不能使用
$"$i"访问参数i。您需要使用变量间接:${!i} -
@Barmar 实际上我从来不知道,谢谢
-
我觉得还是用
while [ $# -gt 0 ]; do ...; shift; done比较好