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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T08:33:45+00:00 2026-06-02T08:33:45+00:00

I am wondering how arguments given to a function in bash can be properly

  • 0

I am wondering how arguments given to a function in bash can be properly “forwarded” to another function or program.

For example, in Mac OS X there is a command line program open (man page) that will open the specified file with its default application (i.e. it would open a *.h file in Xcode, or a folder in Finder, etc). I would like to simply call open with no arguments to open the current working directory in Finder, or provide it the typical arguments to use it normally.

I thought, “I’ll just use a function!” Hah, not so fast there, I suppose. Here is what I’ve got:

function open
{
    if [ $# -eq 0 ]; then
        /usr/bin/open .
    else
        /usr/bin/open "$*"
    fi
}

Simply calling open works great, it opens the working directory in Finder. Calling open myheader.h works great, it opens “myheader.h” in Xcode.

However, calling open -a /Applications/TextMate.app myheader.h to try to open the file in TextMate instead of Xcode results in the error “Unable to find application named ‘ /Applications/TextMate.app myheader.h'”. It seems passing "$*" to /usr/bin/open is causing my entire argument list to be forwarded as just one argument instead.

Changing the function to just use usr/bin/open $* (no quoting) causes problems in paths with spaces. Calling open other\ header.h then results in the error “The files /Users/inspector-g/other and /Users/inspector-g/header.h do not exist”, but solves the other problem.

There must be some convention for forwarding arguments that I’m just missing out on.

  • 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-02T08:33:47+00:00Added an answer on June 2, 2026 at 8:33 am

    You indeed missed "$@", which is designed for this case.

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

Sidebar

Related Questions

Since C+++ allows function overloading, can we overload main() ? For example, int main(const
I was wondering, given the following JSON, how I can produce a ResultSet instance,
I was wondering if it is possible to pass arguments between Mac applications and
I was wondering if there is a good argument for or against using backgrounds
Wondering if there is any way to get the lambda expressions that result from
Wondering if anyone can suggest a good file replication tool that will replicate across
Wondering if there is a good way to generate temporary URLs that expire in
is there a function that would add a time delay between 2 lines of
I don't have formal knowledge of continuations, and am wondering if someone can help
I was wondering if in C/C++ language it is possible to pass arguments to

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.