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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T10:41:12+00:00 2026-06-05T10:41:12+00:00

Ok so I have written a .sh file in Linux Ubuntu and it works

  • 0

Ok so I have written a .sh file in Linux Ubuntu and it works perfectly. However on a Mac it always returns that the file was not found even when it is in the same directory. Can anyone help me out?

.sh file:

if [ ! -f file-3*.jar ]; then
echo "[INFO] jar could not be found."
exit
fi

Just thought I’d add, this isn’t for more than one file, it’s for a file that is renamed to multiple endings.

  • 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-05T10:41:15+00:00Added an answer on June 5, 2026 at 10:41 am

    In a comment to @Paul R’s answer, you said “The shell script is also in the same directory as the jar file. So they can just double click it after assigning SH files to open with terminal by default.” I suspect that’s the problem — when you run a shell script by double-clicking it, it runs with the working directory set to the user’s home directory, not the directory where the script’s located. You can work around this by having the script cd to the directory it’s in:

    cd "$(dirname "$BASH_SOURCE")"
    

    EDIT: $BASH_SOURCE is, of course, a bash extension not available in other shells. If your script can’t count on running in bash, use this instead:

    case "$0" in
        */*)
            cd "$(dirname "$0")" ;;
        *)
            me="$(which "$0")"
            if [ -n "$me" ]; then
                cd "$(dirname "$me")"
            else
                echo "Can't locate script directory" >&2
                exit 1
            fi ;;
    esac
    

    BTW, the construct [ ! -f file-3*.jar ] makes me nervous, since it’ll fail bizarrely if there’s ever more than one matching file. (I know, that’s not supposed to happen; but things that aren’t supposed to happen have any annoying tendency to happen anyway.) I’d use this instead:

    matchfiles=(file-3*.jar)
    if [ ! -f "${matchfiles[0]}" ]; then
        ...
    

    Again, if you can’t count on bash extensions, here’s an alternative that should work in any POSIX shell:

    if [ ! -f "$(echo file-3*.jar)" ]; then
    

    Note that this will fail (i.e. act as though the file didn’t exist) if there’s more than one match.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have written a generic CSV file reader that I'm trying to use to
I have written a database app that imports data from an excel file into
I have written a Linux system wide C++ program /usr/bin/PROG_X that uses a configuration
I have a program written in C++, that opens a binary file(test.bin), reads it
I have a process that is running as a java daemon on Ubuntu Linux.
I have written a C utility for Linux that checks the contents of /proc/net/dev
I have written a linux daemon that will be (and must be) running as
I have a file download script that I have written, which reads files from
I have a linux box (Ubuntu 10.10 server edition) in ec2. I have written
I have written a C++ class for Windows and Linux that creates a memory-mapped

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.