I have a script file (sub.sh
) with the variable inside, for example:
cp -r "$dir1" "$dir2"
chmod 600 "$dir2"
# and many other commands...
I have another script (main.sh
) that prepare the variables, export them to the environment, and run the script file above on another server via SSH. I tried the following command but it doesn't work because the variables are not pre-processed before passing to the server:
cat ./sub.sh | ssh $user@$ip
I know that I can use Heredoc like this:
ssh $user@ip << EOF
cp -r "$dir1" "$dir2"
chmod 600 "$dir2"
# and many other commands...
EOF
but the script is long and I want to split the file to make the code cleaner.
How can I achieve this? Thanks.