如何添加脚本调用Linux命令? [英] How to add a script call to a linux command?

查看:156
本文介绍了如何添加脚本调用Linux命令?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在我的Linux系统脚本调用添加到 LS 命令。该脚本应用户每次执行 LS执行命令。

I want to add in my linux system a script call to the ls command. This script should be executed each time the user execute the ls command.

我试过2解决方案,但两者是有限的:

I tried 2 solutions but both are limited:

1)使用的别名

alias ls="/root/myscript.sh; ls"

但这种方法是有限的,因为用户可以拨打 LS 通过这样一个变量

var="ls"
$var

看到<一个href=\"http://stackoverflow.com/questions/27191119/how-i-can-make-alias-called-when-its-called-by-a-varible\">link了解更多详情

2)使用的功能

我创建了一个函数名为 LS

I create a function with the name ls:

ls() { /root/myscript.sh; /bin/ls $@ }

但这种方法是有限的,因为用户可以调用这个方法 LS

/bin/ls

是否有其他解决方案?

Are there another solution?

推荐答案

您可以把脚本 $ {HOME} LS 说/ myls / LS ,然后设置路径变量 $ {HOME} / myls:$ PATH

You can put a script ls say in ${HOME}/myls/ls and then set the path variable to ${HOME}/myls:$PATH

这篇关于如何添加脚本调用Linux命令?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆