Home > Blockchain >  short way to check (one liner) if a file exists or not
short way to check (one liner) if a file exists or not

Time:04-03

I'm looking for a very short way to check if a file exists or not. If the file exists 1 should be printed and if not 0 should be printed.

The below syntax doesn't print anything? Just an empty output

if [ -f /proc/$pid/stat ]; then echo '1' else echo '0' fi

CodePudding user response:

Try this:

[ -f file ] && echo 1 || echo 0

CodePudding user response:

added some ';'

if [ -f /proc/$pid/stat ]; then echo '1'; else echo '0'; fi
  • Related