I have the following scenario, I have script that runs bash script on another remote machine

The command to ssh is

ssh knode@ 'bash -s' < test.sh


bash ./trigger.sh

trigger.sh (Remote server)

docker build -t nginx .

I need to change the directory before executing the script trigger.sh. For instance like this:

ssh knode@ 'cd /pipeline' 'bash -s' < test.sh 

I tried with cd but I am getting error bash line 0:cd: too many arguments

Help is highly appreciated how to accomplish this, or is there any other way for the above scenario.

  • Can't you add the cd to either test.sh or trigger.sh?
    – terdon
    Nov 17, 2020 at 12:47
  • 1
    Maybe ssh knode@ 'cd /pipeline && bash -s' < test.sh? (untested)
    – Bodo
    Nov 17, 2020 at 12:49

1 Answer 1


You can add the cd to the ssh command:

ssh knode@ 'cd /pipeline && bash -s' < test.sh 

Alternatively, you can add it to either one of the scripts you call. So either test.sh:

cd /pipeline
bash ~/trigger.sh

Or trigger.sh:

cd /pipeline
docker build -t nginx .

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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