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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T22:40:29+00:00 2026-06-02T22:40:29+00:00

I am writing a shell script, or I should more specifically say, a ZSH

  • 0

I am writing a shell script, or I should more specifically say, a ZSH function, and I’m using various brief commands to check the status of things like git repositories, etc.

I’m having a lot of trouble with one particular command, however. In another stackoverflow posting I found the command to print the root folder of a git repository:

git rev-parse --show-top-level

In my actual zsh instance, if I execute

$(git rev-parse --show-top-level)

the appropriate value is returned and all is well. However, this approach inside my script is not working so well. I’ll give a little context:

[ $(git status &>/dev/null) $? -eq "0" ] && {
    git_name=$("git rev-parse --show-top-level")
    echo $(eval $git_name)
}

Now I don’t know about you, but this seems to me to be the wrong way to do this (not the first line; I’m all right with that). The output of this is roughly:

command not found: git rev-parse --show-top-level

The way it seems I should be writing this is:

[ $(git status &>/dev/null) $? -eq "0" ] && {
    git_name=$(git rev-parse --show-top-level)
    echo $git_name
}

The output of this is:

--show-top-level

and the exit status is 0.

My question is, why do neither of these work, and what would be the correct way to implement this? My guess is it has something to do with there being a double-dashed argument after a space, and the last long argument is being treated as a command itself (at least in the second example), but that’s the extent of my intuition.

Help appreciated!

  • 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-02T22:40:41+00:00Added an answer on June 2, 2026 at 10:40 pm

    Try this:

    [ $(git status &>/dev/null) $? -eq "0" ] && {
        git_name=$(git rev-parse --show-toplevel)
        echo $(eval $git_name)
    }
    

    The double-quotes around the git rev-parse are unnecessary and the argument should be --show-toplevel, not --show-top-level.

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

Sidebar

Related Questions

I'm writing a shell script that before running needs to check that system Perl
I'm writing a bit of code to run a shell script using process that
I am writing a shell script to send an email using Linux Mailx ,
I am writing a shell script to do a tail on a growing log
I'm writing a shell script and I need to strip FIND ME out of
I'm writing a shell script to backup the contents of the current directory to
I am writing a POSIX shell script that may or may not receive input
I am writing a simple unix shell script: #!/bin/bash # abort the script if
I'm writing a mini-shell to get more familiar with Unix process management in C.
I'm writing a shell script (tcsh) that is supposed to received 3 parameters or

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.