0

I wish to be able to check if file exist.

if [ -f "/var/run/screen/user/*.$InstanceName" ]; then
        echo -e "screen instance exist"
fi

but the wilcard / joker don't work

How I can pass it ?

WolwX
  • 121
  • 1
  • 15

1 Answers1

1

Your wildcard doesn't work because it's quoted. Unquoting it however might break the [ command as it only expects one filename argument, and if two or more files wore globbed it would break.

In bash you can use compgen that will generate a list of files matching the globbing pattern, it will also set proper exit status if no globs are found, it is a hack? I don't know, but it could look like it:

if compgen -G "/var/run/screen/user/*/$InstanceName" > /dev/null; then
  printf "screen instance exist\n"
fi
Andreas Louv
  • 46,145
  • 13
  • 104
  • 123
  • Thanks andlrc :) That's perfect Just a little correction, my file was /*.$InstanceName" not /*./$InstanceName" – WolwX Jun 11 '16 at 19:37