Bash check if file begins with


















Join Date: Jun Hello, Trying to iterate over set of file in current directory and check if the file name in that folder matches certain string. This is what I have so far. Here I am checking if the file name starts with nexus, if so echo file name to log file. Getting weird syntax errors. Any help is appreciated Code :. Last edited by jim mcnamara; at PM..

Administrator Emeritus. Although I haven't tested this, or your code, and because I don't know what shell you are using, and because it's too late in the evening to play "Let's guess the error message" Code :. Hi Scott, It's failing with the following error.

BTW, it's bash shell. Code :. Last edited by Scott; at PM.. Reason: Guess the code tags. Join Date: Mar Stack Overflow for Teams — Collaborate and share knowledge with a private group. Create a free Team What is Teams?

Collectives on Stack Overflow. Learn more. Asked 7 years, 4 months ago. Active 7 years, 4 months ago. Viewed 27k times. Add a comment. The new upgraded version of the test command [[ double brackets is supported on most modern systems using Bash, Zsh, and Ksh as a default shell.

When checking if a file exists, the most commonly used FILE operators are -e and -f. The first one will check whether a file exists regardless of the type, while the second one will return true only if the FILE is a regular file not a directory or a device.

The most readable option when checking whether a file exists or not is to use the test command in combination with the if statement.

Hope it helps! Isaac Ressler 3 3 3 bronze badges. Victor Victor 2 2 bronze badges. Sign up or log in Sign up using Google. Sign up using Facebook. Sign up using Email and Password. Post as a guest Name. Email Required, but never shown. The Overflow Blog. Podcast Making Agile work for data science. Stack Gives Back Featured on Meta. New post summary designs on greatest hits now, everywhere else eventually. Related



0コメント

  • 1000 / 1000