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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T22:23:25+00:00 2026-06-14T22:23:25+00:00

I have a little shell script that runs anything executable in a designated directory,

  • 0

I have a little shell script that runs anything executable in a designated directory, while passing along two arguments:

#!/bin/sh

cd '/foo'
for s in bar/*;
do [ -x $s ] && $s "$1" "$2" || : ;
done

Is the || : bit serving any purpose? I wanted the executables to be kicked off asynchronously, so I changed the ; to a &, but is there any reason I shouldn’t just do:

#!/bin/sh

cd '/foo'
for s in bar/*;
do [ -x $s ] && $s "$1" "$2" &
done
  • 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-14T22:23:26+00:00Added an answer on June 14, 2026 at 10:23 pm

    || : (which is often spelled || true) means you don’t care whether the command succeeds or not. It forces a successful return status ($?).

    It is good practice to run shell scripts under the shell’s -e option so that errors don’t go unnoticed. This option can be either activated on the shebang line (#!/bin/sh -e) or in the script itself (set -e). It causes errors to abort execution of the script.

    Since in this case you are not running under -e, the || : doesn’t make a different because the shell will ignore the result code anyway if the command fails. Furthermore, you are running a command in the background in this case so checking the return code doesn’t even make sense.

    In general, including || true even if you are not running under -e can be good for two reasons:

    • To make it compatible with -e in case it is ever changed to run under -e.
    • To serve as documentation to someone reading the shell script that you are conscious of the possibility that this command can fail and that such a failure is explicitely OK.
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a simple shell script that builds my Roxygen documents, builds the package,
I have a shell script that pulls the number of online players, but I
I have very little knowledge about unix. My task is to write a shell
What are the things a script should do to ensure that files have been
I was working on a little script that would do some logging for me
I have a shell script I use for deployments. Since I want to capture
Suppose I have this shell script call cpdir: (cd $1 ; tar -cf -
I have this small script that checks if a user name and email exist
when I am working on shell script, I am little frusturate on $@ and
I have set up an automated deployment script (in shell script) for my web

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.