Issue
I have written this thing, but it is not working. I do not know why. The script does not create any alias. Here is my script:
#!/bin/bash
ans=t
while [ $ans == y ]; do
echo "Give alias name"
read name
echo "Give aliast instruction"
read instruction
echo "alias $name='$instruction'"
read ans
done
That is probably simple question, I am totally new to Linux.
Solution
"==" isn't for test equal. It is a simple equal: "=" For check if it is different it is: !=
For define an alias you must use the command alias.
And you must execute the script with the command:
. ./script
The first dot is important if not the script will be executed by a sub-shell and the alias definition will be for the sub-shell, and not the actual shell.
#!/bin/bash
ans=t
while [ $ans != y ]; do
echo "Give alias name"
read name
echo "Give aliast instruction"
read instruction
alias "$name=$instruction"
read ans
done
Answered By - joseyluis Answer Checked By - Marilyn (WPSolving Volunteer)