Ask Ubuntu is a question and answer site for Ubuntu users and developers. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I'm trying to create a bash function so I can get this.

The user, via terminal, goes to the git project path like:


So the user will type open and the browser will open in the like:

So far I have this code:

function teste {
     if [ -d .git ]; then
         remotes=$(git remote -v | awk -F'' '{print $2}' | cut -d" " -f1)
         url="$url$($remotes | cut -d" " -f1)"
         # here I'll open the browser
       # git rev-parse --git-dir 2> /dev/null;
       echo "Not a git repo"

I check if there is a .git folder, if so, I look for the remote origin and get its value that is inside the remote_url. I was trying to concatenate the with the remote_url but no success because the terminal think it is a path so I get this:

bash: bla/my_super_project.git: No such file or directory

How can I concatenate these two values?

share|improve this question
up vote 2 down vote accepted

Problem solved:

function opengit {
    if [ -d .git ]; then
        remotes=$(git remote -v | awk -F'' '{print $2}' | cut -d" " -f1)
        if [ -z "$remotes" ];
            remotes=$(git remote -v | awk -F'' '{print $2}' | cut -d" " -f1)

        remote_url=$(echo $remotes | cut -d" " -f1)
        xdg-open $url
      echo "Not a git repo"
share|improve this answer
For those that doesn't understand what is happening, OP at first tried to execute the command $($remotes | cut -d" " -f1)" with $(...) instead of expanding it as he's doing with ${...}. – Braiam Feb 17 '14 at 2:07

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.