linux中backticks反引号的作用
This is a backtick. A backtick is not a quotation sign. It has a very special meaning. Everything you type between backticks is evaluated (executed) by the shell before the main command (like chown in your examples), and the output of that execution is used by that command, just as if you'd type that output at that place in the command line.
So, what
sudo chown `id -u` /somedir
effectively runs (depending on your user ID) is:
sudo chown 1000 /somedir
\ \ \ \
\ \ \ `-- the second argument to "chown" (target directory)
\ \ `-- your user ID, which is the output of "id -u" command
\ `-- "chown" command (change ownership of file/directory)
`-- the "run as root" command; everything after this is run with root privileges
Have a look at this question to learn why, in many situations, it is not a good idea to use backticks.
Btw, if you ever wanted to use a backtick literally, e.g. in a string, you can escape it by placing a backslash (\) before it.
- 27This explains backticks pretty well, but using
$(your expression)is a better way to do the same thing as$()allows you to nest expressions. for instance:cd $(dirname $(type -P touch))will cd you into the directory containing thetouchcommand – Khaja Minhajuddin Dec 27 '11 at 1:10 - 9@KhajaMinhajuddin You're definitely right about nesting - the above mentioned question covers it in detail. But even though I think it is a good practise to use
$()in most situations, it does not make backticks a worse thing. For practical purposes, one has to admit that they are much faster to type on the command line (2 keystrokes compared to at least 5, includingShift). – rozcietrzewiacz Oct 23 '12 at 13:14 - 2@rozcietrzewiacz Your latter remark is probably true for most keyboards but
$( )is definitely easier to type than` `at least on a French keyboard. – jlliagre May 19 '13 at 20:38 - 1And another +1 for using backticks in the ASCII art ;) – Ignorant Oct 5 '17 at 19:25
- I wrote excape instead of escape and know I cannot fix that 1-letter mistake!
linux中backticks反引号的作用的更多相关文章
- Linux Shell 中的反引号,单引号,双引号
反引号在 (`) 键盘的Tab键的上方.1键的左方.在Linux中起着命令替换的作用.命令替换是指shell能够将一个命令的标准输出插在一个命令行中任何位置.如下,shell会执行反引号中的date命 ...
- Linux Shell中的反引号,单引号,双引号
反引号位 (`) 位于键盘的Tab键的上方.1键的左方.注意与单引号(')位于Enter键的左方的区别. 在Linux中起着命令替换的作用.命令替换是指shell能够将一个命令的标准输出插在一个命令行 ...
- Shell 中的反引号(`),单引号('),双引号(")
在写shell的时候老是傻傻分不清楚,今天来理一理. 1.反引号位 (`) 位于键盘的Tab键的上方.1键的左方.注意与单引号(')位于Enter键的左方的区别. 在Linux中起着命令替换的作用.命 ...
- linux 里的`反引号
Shell中可以将数字或字符直接赋予变量,也可以将Linux命令的执行结果赋予变量,如下: (1) $ count=9 #将数字赋予变量count (2) $ name=" ...
- linux中test与[ ]指令的作用
linux中test与[ ]指令的作用: 在Linux中,test和[ ]功能是一样的,类似于c语言中的( ).不过Linux的test和[ ]是指令.在和if或者while联用时要用空格分开.
- shell脚本中的反引号使用 `
反引号是~的英文切换 在shell脚本中,反引号允许将shell命令的输出赋值给变量. test=`date` 这样shell会执行反引号中的命令.并将执行的结果赋值给变量tests.
- MySQL 中的反引号(`):是为了区分 MySql 关键字与普通字符而引入的符号;一般,表名与字段名都使用反引号。
MySQL 中的反引号(`):是为了区分 MySql 关键字与普通字符而引入的符号:一般,表名与字段名都使用反引号.
- Linux中的Wheel组的作用
原文:http://www.360doc.com/content/11/0505/10/4644186_114496525.shtml Linux中的Wheel组的作用(用自己的话翻译的) (原文) ...
- Linux中PATH环境变量的作用和使用方法
关于PATH的作用:PATH说简单点就是一个字符串变量,当输入命令的时候LINUX会去查找PATH里面记录的路径.比如在根目录/下可以输入命令ls,在/usr目录下也可以输入ls,但其实ls这个命令根 ...
随机推荐
- Go语言有缓冲和无缓冲通道实现样例
感觉可以,但不好用. 应该有封装程序更高的包包吧. package main import ( "math/rand" "fmt" "time&quo ...
- OpenFalcon-SuitAgent
http://www.cnblogs.com/qianlong2016/archive/2016/09/08/5853899.html
- 使用PuTTY连接树莓派
这是 meelo 原创的 玩转树莓派 系列文章 PuTTY是一个支持Telnet.SSH协议,实现远程登录的软件.树莓派的官方操作系统Raspbian默认开启了SSH协议进行登录,这样即使没有专门的显 ...
- crontab定时任务管理
定时任务 添加与编辑任务crontab -e0 */1 * * * command0 */2 * * * command 查询任务是否加了:crontab -l #查看当前用户crontab -l ...
- php api接口校验规则示例
1.发送 /** * 客户端请求 * @param url 接口地址 * @param array $params(post) * @return json * @throws Exception * ...
- ubuntu下dpkg/apt的一些常用命令
apt-get update 更新源(硬盘缓存的包的版本等)apt-get upgrade 更新包(更新系统中已安装的包,依据缓存包的版本更新)apt-get dist-upgrade 升级系统apt ...
- Codeforces 429 B. Working out-dp( Codeforces Round #245 (Div. 1))
B. Working out time limit per test 2 seconds memory limit per test 256 megabytes input standard inpu ...
- 转:java-Servlet开发
转:http://www.cnblogs.com/xdp-gacl/p/3760336.html 一.Servlet简介 Servlet是sun公司提供的一门用于开发动态web资源的技术. Sun公司 ...
- VMware Workstation的三种网络连接方式
桥接模式(Bridged).NAT模式(地址转换模式).仅主机模式(Host-Only) 桥接模式就是将主机网卡与虚拟机的网卡利用虚拟网桥进行通信.在桥接的作用下,类似于把物理主机虚拟为一个交换机,所 ...
- HTML5 form内button
突然发现奇怪的事 在html5 中bottn 的type不是submit但是单击的时候它自己就提交表单了. 然后在一查就看到 问题解决,加上type=“button”
- Linux Shell 中的反引号,单引号,双引号