I have this  echo $line Thisisaline.   I was wondering why is this not working:  if [[ "$line" =~ "[a-zA-Z]+\.$" ]] ; then echo "hello"; fi   Above regex gives no output.
10330
The following code  number=1 if [[ $number =~ [0-9] ]] then   echo matched fi   works. If I try to use quotes in the regex, however, it stops:  number=1 if [[ $number =~ "[0-9]" ]] then   echo matched fi   I tried "\[0-9\]", too. What am I missing?  Funnily enough,  suggests this should work.  Bash version 3.2.39.
25194
I am trying to pull logs and doing few others things directly. written a small line BASH but not working. I am sure thats with IF Condition.    sed -rne '/21:25:07/,/21:50:07/ p'  server.log.2015-04-21 &gt; /tmp/filename.log ; du -sh  /tmp/filename.log ;  if [`du -sh  /tmp/filename.log` -gt 0] then gzip /tmp/filename.log ;
33328
I notice a lot of bash utilities like ls, cp, mv, grep use regular expressions and pattern matching. For instance symbols like * [] {} etc.   However, I find this to be different in some regard to other regular expression tutorials I find on the Internet. Is there a specific standard that these utilities follow or a comprehensive list of shortcuts somewhere?   Thank you
2830
I want to check if a variable has a valid year using a regular expression. Reading the  I understand I could use the operator =~  Looking at the example below, I would expect to see "not OK" but I see "OK". What am I doing wrong?  i="test" if [ $i=~"200[78]" ] then   echo "OK" else   echo "not OK" fi
117335
I'm trying to check if an input is an integer and I've gone over it a hundred times but don't see the error in this. Alas it does not work, it triggers the if statement for all inputs (numbers/letters)  read scale if ! [[ "$scale" =~ "^[0-9]+$" ]]         then             echo "Sorry integers only" fi   I've played around with the quotes but either missed it or it did nothing. What do I do wrong? Is there an easier way to test if an input is just an INTEGER?
20912
This will notify us if the file is empty:  [[ ! -s $file ]] &amp;&amp; echo "hello there I am empty file !!!"   But how to check if a file has blank spaces (spaces or tabs)?   empty file can include empty spaces / TAB
690
What is the difference between \par, \newline, \\ and blank lines? When should I use which one?
62323
I've run across some scripting like this recently:  ( set -e ; do-stuff; do-more-stuff; ) || echo failed   This looks fine to me, but it does not work!  The set -e does not apply, when you add the ||.  Without that, it works fine:  $ ( set -e; false; echo passed; ); echo $? 1   However, if I add the ||, the set -e is ignored:  $ ( set -e; false; echo passed; ) || echo failed passed   Using a real, separate shell works as expected:  $ sh -c 'set -e; false; echo passed;' || echo failed failed   I've tried this in multiple different shells (bash, dash, ksh93) and all behave the same way, so it's not a bug.  Can someone explain this?
10243
I'm quite confused about the following regular expressions I found in a shell script:  ${0##*/} ${0%/*}   How do they work?
11588
I'm trying to use Bash string substitution to combine an array. Desired output: cat,dog,fish  This works, but isn't there a way to do with without piping? #!/bin/bash  words=(cat dog fish)  echo &quot;${words[@]}&quot; | sed 's/ /,/g'  I've been trying this, which doesn't work. echo &quot;${words[@]// /,/}&quot;
56895
I'm starting with bash and I found the following:  if test $first -lt $second then   echo $first is lower than $second else   if test $first -gt $second   then     echo $first is higher than $second   else     echo $first and $second are equals   fi fi   For reading the script and executing it, I know what it does, but not what -lt and -gt are for.  Can somebody tell me what is the name of that kind of 'tool' and what they(-lt and -gt) do? Thanks!
26761
I was viewing my .bash_profile file, and I saw this written inside a block of if statement:  if [ -f ~/.bashrc ]; then        . ~/.bashrc    Can someone explain what the second line is actually doing?
20352
Is it possible to detect a valid regular expression with another regular expression?  If so please give example code below.
34578
#!/bin/bash INT=-5  if [[ "$INT" =~ ^-?[0-9]+$ ]]; then  echo "INT is an integer."  else  echo "INT is not an integer." &gt;&amp;2  exit 1  fi   What does the leading ~ do in the starting regular expression?
46012
I am trying to find all matches in a string that begins with | |.    I have tried: if ($line =~ m/^\\\|\s\\\|/) which didn't work.   Any ideas?
3936
I need to find a string and need to print the line above it.   case1: The same line won't have the more than one matching pattern   ie)  consider a file containing  $cat &gt; para returns between the paragaraphs italic or bold     quotes by placing italic   Here i need to find for italic, and i need to get the output as below   returns between the paragaraphs quotes by placing   How can i get the output like this?
8433
How can I echo "$" in a here-doc in bash?  For example, I want to have a file with the content on remote server like $ABC=home_dir.  $ ssh hostname sudo -s &lt;&lt;EOF echo "$ABC=home_dir" &gt; file EOF   But it would be treated as a variable. How can I print a literal $?