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 8275697
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T08:09:36+00:00 2026-06-08T08:09:36+00:00

I have to write a shell script and i don’t know how to go

  • 0

I have to write a shell script and i don’t know how to go about it.
Basically i have to write a script where i’d find a file ( it could be possibly named differently). If either file exists then it must be executed, if it returns a 0 ( no error), it should continue the build, if it’s not equal to 0 ( returns with error), it should exit. If either file is not found it should continue the build.

the file i have to find could be either file.1 or file.2 so it could be either named (file.1), or (file.2).

some of the conditions to make it more clear.
1) if either file exists , it should execute – if it has any errors it should exit, if no errors it should continue.
2) none could exist, if that’s the case then it should continue the build.
3) both files will not be present at the same time ( additional info)

I have tried to write a script but i doubt it’s even closer to what i am looking for.

if [-f /home/(file.1) or (file.2)]
then 
  -exec /home/(file.1) or (file.2)
   if [ $! -eq 0]; then
   echo "no errors continuing build"
   fi
   else
   if [ $! -ne 0] ; then
   exit ;
   fi
else 
   echo "/home/(file.1) or (file.2) not found, continuing build"
fi

any help is much appreciated.

Thanks in advance

  • 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-08T08:09:38+00:00Added an answer on June 8, 2026 at 8:09 am
    DOIT=""
    for f in file1.sh file2.sh; do
      if [ -x /home/$f ]; then DOIT="/home/$f"; break; fi
    done
    if [ -z "$DOIT" ]; then echo "Files not found, continuing build"; fi
    if [ -n "$DOIT" ]; then $DOIT && echo "No Errors" || exit 1; fi
    

    For those confused about my syntax, try running this:

    true && echo "is true" || echo "is false"
    false && echo "is true" || echo "is false"
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to write a shell script wherein I have to find out the
I have a project that generates a shell script at CMake time (with file(WRITE
I have very little knowledge about unix. My task is to write a shell
I don't have much practical programming experience. I wrote a function in shell script
This is a crude korn shell script that someone else wrote. I don't know
I have to write the shell script, which will run on cygwin and build
I have to use windows to write some shell scripts. I decided to use
qichunren@zhaobak:~> gem install hpricot ERROR: While executing gem ... (Gem::FilePermissionError) You don't have write
I have a perl script (or any executable) E which will take a file
I have a simple question. I know that shell scripts are slow/ineffective when it

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.