Silly question, but since I'm such a newbie at Linux OS, I'm having trouble to make this simple script to echo the result of PS1
.
If I type echo $PS1
in bash, it shows me the result, but not in the script. It returns blank.
Example:
#!/bin/bash
ps1=$(echo $PS1)
echo $ps1
Any tips for a begginer?
Thanks in advance.
Other answers are correct. If you add the -i
flag to your shebang, that signals bash that it's supposed to be an interactive shell, so it will read your ~/.bashrc -- see https://www.gnu.org/software/bash/manual/bashref.html#Invoking-Bash
#!/bin/bash -i
ps1="$PS1"
echo "$ps1"
PS1
is a variable which is not "exported", so it is only visible within the shell, but not from any subprocess such as the script's.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With