Home > computers > linux > bash > bashstringcomparison | About

  • =~ for regular expressions (not to be confused with the binary ~= operator), do not use quotes nor double quotes, juste the string
  • = for regular shell globs, do not use quotes nor double quotes either

Example

Remove everything except two folders named backup.algerian-radio.dz and algerian-radio.dz

for file in *; 
  do 
    if [[ "$file" != backup.algerian-radio.dz && "$file" != algerian-radio.dz ]]; 
    then 
      echo remove "$file"; rm -rf "$file";
    else 
      echo keep "$file"; 
    fi; 
done;

contact : @ychaouche yacinechaouche at yahoocom


QR Code
QR Code Example (generated for current page)