문제

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?

도움이 되었습니까?

해결책

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.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top