Lucas Muller
Lucas Muller

Reputation: 101

Bash line to check if a file path exists using wildcards in filepath

I am trying to check if a file path exists and if it does to complete the pwd command. if a file path does not exist then i want it to break and move on to the next command.

while [ -d folder1/*/stack ]; do pwd; break; done; while [<next set of commands>]...ect

i get binary operator expected error.

Upvotes: 2

Views: 1778

Answers (1)

Oliver Gaida
Oliver Gaida

Reputation: 1920

You can use ls. If ls is successfull, then pwd will run:

ls folder1/*/stack > /dev/null 2>&1 && pwd
# next command

Upvotes: 2

Related Questions