Created
June 21, 2024 22:38
-
-
Save JeanCarlosChavarriaHughes/e9bd316b697f4e61e84c9d01079c779c to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
VARIABLE_NAME="NODE_VERSION" | |
VARIABLE_VALUE="21.7.1" | |
PROFILE_FILE="$HOME/.bash_profile" | |
# Check and append using awk | |
if ! awk -v var="$VARIABLE_NAME" 'BEGIN { found=0 } /^export/ { if ($0 ~ "export " var "=") found=1 } END { exit !found }' "$PROFILE_FILE"; then | |
echo "export $VARIABLE_NAME='$VARIABLE_VALUE'" >> "$PROFILE_FILE" | |
echo "Variable $VARIABLE_NAME added to $PROFILE_FILE" | |
else | |
echo "Variable $VARIABLE_NAME already exists in $PROFILE_FILE" | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment