Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7796891
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T23:30:39+00:00 2026-06-01T23:30:39+00:00

In a (ba)sh script, how do I ignore file-not-found errors? I am writing a

  • 0

In a (ba)sh script, how do I ignore file-not-found errors?

I am writing a script that reads a (partial) filename from stdin, using:

read file; $FILEDIR/$file.sh

I need to give the script functionality to reject filenames that don’t exist.

e.g.

$UTILDIR does NOT contains script.sh
User types script
Script tries to access $UTILDIR/script.sh and fails as

./run.sh: line 32: /utiltest/script.sh: No such file or directory

How do I make the script print an error, but continue the script without printing the ‘normal’ error?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-01T23:30:40+00:00Added an answer on June 1, 2026 at 11:30 pm

    You can test whether the file exists using the code in @gogaman’s answer, but you are probably more interested in knowing whether the file is present and executable. For that, you should use the -x test instead of -e

    if [ -x "$FILEDIR/$file.sh" ]; then
       echo file exists
    else
       echo file does not exist or is not executable
    fi
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a small script we're using to read in a CSV file containing
I understand that a .gitignore file cloaks specified files from Git's version control. How
I'm using a PHP script to stream a live video (i.e. a file which
I want to extract data from HTML table using Python script and save it
I am writing a python converter that takes in an .obj file and outputs
Trying to write a python script to extract lines from a file. The file
I am trying to write a bash script that goes through a file line
The script runs fine when stdout/stderr are not redirected. When I add both stderr
The script below resides in my theme's functions.php file. It is designed to show
The script below worked on my Mac OS X. I'm now using Ubuntu OS,

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.