0

Goal:

  1. login to a remote system, 2) ask for user input, 3) store the first 4 characters of the input string in a file on the remote system.

What I have:

#!/bin/bash
USERNAME=someUser
HOST="host1"
SCRIPT="echo Enter the string; read -n 4 str; echo $str > file.txt"
ssh -l ${USERNAME} ${HOSTNAME} "${SCRIPT}"

Problem:

The file.txt does not contain the string- it is empty! If I echo $str after the read, it seems empty. Am I missing anything?

3
  • Use single-quotes, not double quotes, when assigning to SCRIPT. Commented Sep 17, 2020 at 19:33
  • Right now, the $str is evaluated on what str has during the SCRIPT= line. Commented Sep 17, 2020 at 19:33
  • perfect! thanks @CharlesDuffy Commented Sep 17, 2020 at 19:54

0

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.