Question

I'm trying to write bash script, that contains the Tmux commands:

#!/bin/bash
# script.sh
tmux -2 new-session -s name 'another_script.sh param'

#!/bin/bash
# another_script.sh
echo $1 > test

It will be ok, if the another_script.sh has been executed with the hardcoded param value

tmux -2 new-session -s name 'another_script.sh param_value'

But when I'm trying to use a variable

tmux -2 new-session -s name 'another_script.sh $1'

value of the argument $1 hasn't been passed into another_script.sh

Anybody knows what I'm doing wrong?

Was it helpful?

Solution

Variables don't expand in single quotes. Use double quotes instead:

tmux -2 new-session -s name "another_script.sh $1"

PS: shellcheck would have automatically told you this.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top