bash notes

Snippet

Notes on bash

# length of a variable
size=${#myvar} 
 
# confirming the length
$ echo $size
# => 11
 
# use in an if statement
if [ ${#size} < 4 ]; then
  echo "mystr can't be fewer than 4 characters"
  exit
fi
 
barf=1
if [[ $barf ]] then; 
  ...
fi
 
if [[ ! $id ]]; then
  echo "doesn't exist"
else
  echo "exists. $id"
fi

Add new comment

Plain text

  • No HTML tags allowed.
  • Lines and paragraphs break automatically.