I wrote a small bash script called "isinFile.sh" to check if the first term specified in the script in the file.txt file can be found:
#!/bin/bash FILE="file.txt" if [ `grep -w "$1" $FILE` ]; then echo "true" else echo "false" fi
However running the script as
> ./isinFile.sh -x
breaks the script, as it is -xinterpreted grepas an option. So I improved my script
-x
grep
#!/bin/bash FILE="file.txt" if [ `grep -w -- "$1" $FILE` ]; then echo "true" else echo "false" fi
using --grep as an argument. Now run
--
> ./isinFile.sh -x false
works. But uses the --correct and only way to prevent code / option input in a bash script? I did not see it in the wild, I only found it in ABASH: search for errors in bash scripts .
grep -w -- ...
-
( ). , . - ; ".{0}-x" , ., ,
".{0}-x"
grep -w ".{0}$1" ...
.
( -, ) script: grep [ (aka test) , ' , . , [ . , , 0 -eq 2, "0" - [, , 0 2, script false, , .
[
test
0 -eq 2
- - ( ) - , ( -q grep ). , : if [ "$(grep -w -- "$1" "$FILE")" ]; then ( , $() backquotes, , $ - , , ).
-q
if [ "$(grep -w -- "$1" "$FILE")" ]; then
, , , , - :
rm ./-x
rm /path/to/-x
Source: https://habr.com/ru/post/1749361/More articles:Silverlight 4: ToolTipService - tooltipThe Most Effective ASP.NET Web Control Set - asp.netCompilation errors calling find_if using a functor - c ++How do Django signals work? - pythonusing standalone JdcbTemplate - javaThe easiest way to get started with debugging PHP (Drupal) - debuggingASP.NET MVC: Why can't I set ShowForEdit model metadata with an attribute? - asp.net-mvcOverride DEFINE in setup.cfg file in source eggs. - pythonDjango username in url, instead of id - urlRegex replace string in HTML but not inside link or header - htmlAll Articles