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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T00:17:21+00:00 2026-05-26T00:17:21+00:00

the more I learn bash the more questions I have, and the more I

  • 0

the more I learn bash the more questions I have, and the more I understand why very few people do bash. Easy is something else, but I like it.

I have managed to figure out how to test directories and there writablity, but have a problem the minute I try to do this with a remote server over ssh. The first instance testing the /tmp directory works fine, but when the second part is called, I get line 0: [: missing]’`

Now if I replace the \” with a single quote, it works, but I thought that single quotes turn of variable referencing ?? Can someone explain this to me please ? Assuming that the tmp directory does exist and is writable, here the script so far

#!/bin/bash
SshHost="hostname"
SshRsa="~/.ssh/id_rsa"
SshUser="user"
SshPort="22"
Base="/tmp"
Sub="one space/another space"

BaseBashExist="bash -c \"[ -d \"$Base\" ] && echo 0 && exit 0 || echo 1 && exit 1\""
SSHBaseExist=$( ssh -l $SshUser -i $SshRsa -p $SshPort $SshHost ${BaseBashExist} )
echo -n $Base
if [ $? -eq 0 ]
    then
        echo -n "...OK..."
    else
        echo "...FAIL"
        exit 1
fi
BaseBashPerm="bash -c \"[ -w \"$Base\" ] && echo 0 && exit 0 || echo 1 && exit 1\""
SSHBaseExist=$( ssh -l $SshUser -i $SshRsa -p $SshPort $SshHost ${BaseBashPerm} )
if [ $? -eq 0 ]
    then
        echo "...writeable"
    else
        echo "...not writeable"
fi

BaseAndSub="$Base/$Sub"
BaseAndSubBashExist="bash -c \"[ -d \"$BaseAndSub\" ] && echo 0 && exit 0 || echo 1 && exit 1\""
SSHBaseAndSubExist=$( ssh -l $SshUser -i $SshRsa -p $SshPort $SshHost ${BaseAndSubBashExist} )
echo -n $BaseAndSub
if [ $? -eq 0 ]
    then
        echo -n "...OK..."
    else
        echo "...FAIL"
        exit 1
fi
BaseAndSubBashPerm="bash -c \"[ -w \"$BaseAndSub\" ] && echo 0 && exit 0 || echo 1 && exit 1\""
SSHBaseAndSubPerm=$(  ssh -l $SshUser -i $SshRsa -p $SshPort $SshHost ${BaseAndSubBashPerm} )
if [ $? -eq 0 ]
    then
        echo -n "...writeable"
    else
        echo "...not writeable"
fi
exit 0
  • 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-05-26T00:17:22+00:00Added an answer on May 26, 2026 at 12:17 am

    You are fine with single quotes in this context; by the time the script is seen by the remote bash, your local bash has already substituted in the variables you want to substitute.

    However, your script is a total mess. You should put the repetitive code in functions if you cannot drastically simplify it.

    #!/bin/bash
    
    remote () {
        # most of the parameters here are at their default values;
        # why do you feel you need to specify them?
        #ssh -l "user" -i ~/.ssh/id_rsa -p 22 hostname "$@"
        ssh hostname "$@"
        # —---------^
        # if you really actually need to wrap the remote
        # commands in bash -c "..." then add that here
    }
    
    exists_and_writable () {
        echo -n "$1"
    
        if remote test -d "$1"; then
            echo -n "...OK..."
        else
            echo "...FAIL"
            exit 1
        fi
    
        if remote test -w "$1"; then
            echo "...writeable"
        else
            echo "...not writeable"
        fi
    }
    
    Base="/tmp"
    # Note the need for additional quoting here
    Sub="one\\ space/another\\ space"
    
    exists_and_writable "$Base"
    
    BaseAndSub="$Base/$Sub"
    
    exist_and_writable "$BaseAndSub"
    
    exit 0
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am constantly looking to learn more about MVVM but I feel like I
I am trying to learn more about the DOM and have been writing some
I am trying to learn more about the PHP function sprintf() but php.net did
I'm new to bash, but eager to learn. Right now I'm stealing useful scripts
I am trying to learn more about the mechanics of executable files, but I
As I learn more about KVO and KVC, I have become curious - How
I'm trying to learn a bit about bash-commands -- more specifically about backup-scripts. Unfortunately,
In an effort to learn more about php and mysql, I have been working
I am trying to learn more about websocket and its internal implementations. But still
To practice and learn more about databases, I’m searching besides the well-known databases like

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.