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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T04:50:48+00:00 2026-06-16T04:50:48+00:00

I am attempting to write a shell script which SSHs into a server and

  • 0

I am attempting to write a shell script which SSHs into a server and then prompts the user to enter a file/folder.

ssh $SERVER <<EOF
cd downloads/
read -e -p "Enter the path to the file: " FILEPATH
echo $FILEPATH
eval FILEPATH="$FILEPATH"

echo "Downloading $FILEPATH to $CLIENT"
EOF

I am using heredoc instead of double quotes after the SSH to execute these commands because my shell script is rather large and I don’t want to be escaping every double quote.

When I was using double quotes, the prompt worked fine. However, now that I am using heredoc, the prompt no longer works.

What can I do to get the prompt to work with heredoc? And if not, is there any way I layout my script so that the prompt does work without wrapping everything in double quotes and escaping, like so:

ssh $SERVER "
cd downloads/
read -e -p \"Enter the path to the file: \" FILEPATH
echo $FILEPATH
eval FILEPATH=\"$FILEPATH\"

echo \"Downloading $FILEPATH to $CLIENT\"
exit
"
  • 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-16T04:50:49+00:00Added an answer on June 16, 2026 at 4:50 am

    If you don’t need any variables from the client, why not try – and ssh -t might be useful.

    export CLIENT=me 
    
    CMDS=$(cat <<CMD 
    cd downloads/ 
    read -e -p "Enter the path to the file: " FILEPATH 
    echo \$FILEPATH 
    eval FILEPATH="\$FILEPATH" 
    
    echo "Downloading \$FILEPATH to $CLIENT" 
    CMD 
    ) 
    
    ssh localhost -t "$CMDS" 
    

    Note that if your only issue with double-quotes is escaping, and you do not plan on
    using ' single quotes in your script, then you can ust do this:

    ssh -t $SERVER '
    # your script, unescaped.
    # if you want access to a locally defined variable,
    echo "CLIENT is '$CLIENT'."
    '
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm attempting to write a simple one-line script to ssh into a remote host,
I am new to power-shell and attempting to write a VMreset script. I have
I'm attempting to write a menu driven modular perl script that will capture user
I am attempting to write out an Excel file from an ASP.NET web server
I am curretnly attempting to write a script in python that allows me to
I am attempting to write an Android app which will allow me to read
I have been attempting to write a VBA Script that can parse out other
I'm attempting to write a very basic script using javascript. What I want to
i'm attempting to write the result of the $x = [System.Net.Dns]::GetHostAddresses($name) statement into my
I am attempting to write a 'User Control' in WinForms .NET (not ASP.NET). The

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.