我正在做以下事情:
if [ -f $FILE ] ; then
echo "File exists"
fi
Run Code Online (Sandbox Code Playgroud)
但我希望它-f不区分大小写.也就是说,如果FILE是/etc/somefile,我希望-f识别/Etc/SomeFile.
我可以用glob部分解决它:
shopt -s nocaseglob
TARG='/etc/somefile'
MATCH=$TARG* #assume it returns only one match
if [[ -f $MATCH ]] ; then
echo "File exists"
fi
Run Code Online (Sandbox Code Playgroud)
但不区分大小写的globbing仅适用于文件名部分,而不适用于完整路径.所以,如果TARG是行不通的话/Etc/somefile.
有没有办法做到这一点?
我正在寻找一种在多个列表之间映射可变函数的简明方法,但是我不想像MAPCAR那样将列表作为单独的参数传递,而是要传递包含任意数量的列表的单个列表,并通过这些包含的列表进行映射。我事先不知道封闭列表中有多少个列表,因此我无法对其进行分解。
我曾尝试以各种方式将MAPCAR和APPLY结合起来,但无法弄清楚。我是否必须放弃使用MAP并只显式地编写迭代?
这是一个执行我想要的功能的函数:
(defun map-within (fn list-of-lists &optional(maptype #'mapcar))
"Map FN on the lists contained in LIST-OF-LISTS"
(cond ((null list-of-lists) nil)
((null (cdr list-of-lists)) (car list-of-lists))
(t
(funcall maptype fn
(car list-of-lists)
(map-within fn (cdr list-of-lists) maptype)))))
Run Code Online (Sandbox Code Playgroud)
哪里
(map-within #'+ '((1 2 3) (10 20 30) (100 200 300))) => (111 222 333)
Run Code Online (Sandbox Code Playgroud)
由地图制成的lambda是否有某种神奇的应用,可以仅用一行来表达呢?
我有一个功能,用于使用一个文本框在我的网络中搜索内容,<input class="form-control" id="search" type="text" placeholder="Search" />显示内容位于不同的面板中,所以这是我的script.
$('#search').keyup(function () {
var term = $(this).val();
if (term != '') {
$('.panel').hide();
$('.panel').filter(function () {
return $(this).text().indexOf(term) > -1
}).show();
} else {
$('.panel').show();
}
});
Run Code Online (Sandbox Code Playgroud)
这工作正常,但仅适用于完全匹配,如果我在文本框中写入Hello只显示Hello单词但我需要显示hello,hEllO或HELLO, 所有字符串,无论大小写。
非常感谢任何帮助,抱歉我的语法不好。