Geting Start:
- Create shell script like:
userHabitInit.sh
$vim ~/userHabitInit.sh
- Input all these code below, you can add another alias if you need.
#!/bin/bash
#Set a name and path of a new user habit shell script.
habitShell=xxx/userHabit.sh
#Set user habit.
userHabit='
alias tc="cd xx"
alias lib="cd xxx"
alias catout="tail -f xxx"
alias lany="ls -la xx*xx*"
tomcatBin=xxxx
function tomcatRestart {
${tomcatBin}/shutdown.sh
${tomcatBin}/catalina.sh jpda start
}
alias catrs="tomcatRestart"
'
#Set a nick name for starting this user habit configuration.
nickName="habit"
#Game start:
if [ -a ${habitShell} ];then
echo "[Warning]:"
echo "${habitShell} exist!"
echo "Please check it or remove it first, and then retry."
echo "Exit..."
else
#touch xxxx/habitShell.sh
touch ${habitShell}
#Create some new 'alias' or something useful user habits.
echo "#!/bin/bash\n${userHabit}" >> ${habitShell}
#Make these order effective permanently in each user account(root & zxin10).
echo "alias ${nickName}=\"source ${habitShell}\"" >> ~/.bashrc
echo "alias ${nickName}=\"source ${habitShell}\"" >> /home/zxin10/.bashrc
#Change the owner of 'userHabit.sh' script.
chmod 770 xxx/userHabit.sh
chown xxx xxx/userHabit.sh
source ~/.bashrc
fi
-
upload this shell script and:
$chmod 770 ~/userHabitInit.sh
-
Init :
$source ~/userHabitInit.sh
-
Use $
habit
command to load all alias settings.
No. | Command | Description |
---|---|---|
1 | $tc
|
go to tomcat catalogs |
2 | $lib
|
change to lib catalogue |
3 | $lany
|
show all files like "xxx" |
4 | $catout
|
show tomcat working logs |
5 | $catrs
|
restart tomcat |
6 | $tomcatRestart
|
restart tomcat |
Problems :
Line break is not the same between Windows and Unix, it is \r\n
in Windows though \n
in Unix. If don't convert the problem will called this error:
/bin/bash^M: bad interpreter: No such file or directory
?
Solution:
- $
vim userHabitInit.sh
- Use
:set ff=unix
to convert the file to Unix format - Then use
source ~/userHabitInit.sh
to load all settings.
网友评论