"alias" Batch Setting Script

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.
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

相关阅读更多精彩内容

  • PLEASE READ THE FOLLOWING APPLE DEVELOPER PROGRAM LICENSE...
    念念不忘的阅读 14,599评论 5 6
  • NAME dnsmasq - A lightweight DHCP and caching DNS server....
    ximitc阅读 7,956评论 0 0
  • 在简书上面看到一些码友的文章里边,用“简笔画” 画的一些生活真的挺有意思,而且她们在工作运用简笔画做的笔记还是演讲...
    伏晶之心阅读 1,445评论 0 0
  • 在闹嚷嚷的商场,她没有想到,会碰到他。 她当时正抓起一把金黄色的小米细看。最近她老公胃不好。据说小米养胃,是个好东...
    东方地秀阅读 2,972评论 3 5
  • 大家好,我是维维你还记得吗?在生活中我们经常会看见 ,一些大人帮自己的小孩挖耳屎,但是你知道其中的危害吗?今天...
    雨之春阅读 3,401评论 0 0

友情链接更多精彩内容