select r.name, count(p.id) from persons as p join rides as r on p.fav_ride_id = r.id group by r.id order by count(p.id) desc limit 2;
一整就用到
$PWD
$PATH
$HOME
The shell has variables to access arguments in the procedures, to define the environment and the like. Shell variables are:
$1 # argument ($0..$9, $#)
PATH # predefined symbol
mydir # user defined symbol
Symbols are created using the = operator (no blanks allowed), thus:
mydir=`pwd` # mydir keeps track of current working directory
The symbol mydir can be used to restore the current working directory, as shown below:
$ cd gks/work # change working directory
$ mydir=`pwd` # set symbol mydir
$ cd # restore root directory
$ cd new # move to new directory
$ cd $mydir # return to previous directory
The command set lists all available symbols in the current session. Any variable is defined only in the current subshell, to make the variable global to any subshell use the export command as shown below.
Local definition of mydir:
$ mydir=`pwd`
$ echo $mydir # prints the current directory (i.e. /u/code or the like)
$ sh # run new shell
$ echo $mydir # mydir is not defined at subshell
Global definition of mydir:
$ mydir=`pwd`; export mydir
$ echo $mydir # prints value of current directory (i.e. /u/code ...)
$ sh # run new shell
$ echo $mydir # value of mydir is same as above (i.e. /u/code ...)
Predefined variables like PATH can be changed only at current shell level:
$ PATH=$PATH:/new
To change the variable in .profile and have it active the (dot) command must be used:
$ . ./.profile
The command:
$ sh .profile
does not change the value of PATH as it is executed in a subshell, using . (dot) means use .profile as standard input so that the commands are really executed in the active shell.
In case some applications require to change the value of PATH during a session without modifying .profile, edit a file (ex. newp) containing a command as follows:
$ PATH=$PATH:/newdir
then type:
$ . ./newp
to set the new path value. In case you want to restore the default PATH, use:
$ cd
$ . ./.profile
to reset the .profile setup.
分享到:
相关推荐
shell script学习中的笔记
一直很喜欢写unix shell script, 因为写那么一点点东西可以有那么多效果,投入小,产出大,爽啊. 在写IBM AIX K Shell script时,感觉不那么友好,主要是有一些格式细节要求比较严格,不太习惯,后来写惯了也就好了,下面的...
shfmt_v3.1.2_windows_amd64.exe shfmt_v3.1.2_windows_386.exe 解决idea would you like to install a shell script formatter?的问题
身為 UNIX 系統管理者除了要熟悉 UNIX 指令外,我們最好學會幾種 scripts 語言,例如 shell script 或 perl。學會 script 語言後,我們就可以將日常的系統管理工作寫成一支執行檔,如此一來,在管理系統時就可以更加...
shell script 语言教程 非常好的入门级材料,适合速成。
Shell脚本编程(scripting)的技巧永远不会过时:它们可以让UNIX充分发挥其真实的潜能。对UNIX的用户与系统管理者而言,编写Shell脚本是必须的工作,它可以让你快速地控制与定制任何UNIX系统的强大功能。有了Shell...
Linux shell Script
Jenkins构建Execute shell script on remote host using ssh命令;JenkinsSSH执行命令;
shell script 交互语法shell script 交互语法shell script 交互语法shell script 交互语法shell script 交互语法shell script 交互语法shell script 交互语法shell script 交互语法
shellscript shellscript
shell script 的语法、判断式、循环、括号的区别、跟踪与调试。
在Jenkins构建springboot项目自动部署的时候,配置远程执行Dockerfile所在服务器的SSH命令,这里把完整的命令贴出来,详细搭建过程见我的博客《基于Jenkins+Gitlab+Docker实现SpringBoot项目自动部署》
微软操作系统 windows脚本编程,适合初学者。
C Shell 教程 英文版 2007年5月出版
dd ssd的shell script
Premier Press - Microsoft Windows Shell Script Programming for the Absolute Beginner.pdf Premier Press - Microsoft Windows Shell Script Programming for the Absolute Beginner.pdf Premier Press - ...