PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Sunday, August 21, 2022

[FIXED] How to access environmental variables inside sshpass interactive mode

 August 21, 2022     bash, environment-variables, heredoc, shell, sshpass     No comments   

Issue

The below shell script snippet prints the environmental variable outside of sshpass, but not inside.

#!/bin/bash

[[ $1 = '' ]] && BRANCH="develop" || BRANCH=$1

echo $DESTINATION_FOLDER // prints from env

sshpass -p $PASSWORD ssh -o StrictHostKeyChecking=no $SERVER <<-'ENDSSH'

    echo $DESTINATION_FOLDER // doesn't print anything, output: empty

    exit
ENDSSH

Am I missing any option to be passed to the interactive mode with sshpass so that it can read environmental variables defined in the local system?


Solution

I suggest to replace 'ENDSSH' with ENDSSH to allow bash to interpret the variable in your here-document.

See: https://en.wikipedia.org/wiki/Here_document#Unix_shells



Answered By - Cyrus
Answer Checked By - Mary Flores (PHPFixing Volunteer)
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing