[英]Fish Shell: validate if string contains substring
目前,我正在尝试验证包含路径的字符串是否包含特定字符串。
我已经尝试过bash比较:
和
我也尝试使用“包含”关键字。 但是我不确定是否应该将它与字符串一起使用。
不幸的是,这些尝试都失败了。 :/
function next_dir
set foundcwd 0
set cwd $PWD
set error 'There is no next directory to navigate to...'
if [ -z $cwd ]
echo $error
else
echo $cwd
for d in ../*/
set needle (string split "/" -- $d)[2]
if [ $foundcwd = 1 ]
cd $d
break
end
if [ $cwd =~ $needle ]
$foundcwd = 1
end
end
end
end
我函数的目标是导航到下一个(同级)目录。
/ mnt / c / workingdirectory / repoA->当前目录/ mnt / c / workingdirectory / repoB->导航到repoB
您想要string match
。
if string match -q -- $needle $path
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.