Usage of $(), $(()), and ${} in Shell

  
 

When we write the shell, there will be such a scene:

For example: I want to back up the passwd file and back it up to bak_path=”/mnt/sql_bak/”

And the file name is bak?

Get used to the shell like this:
#!/bin/shbak_path="/mnt/bak/"cp $/etc/passwd $bak_pathbak

But this will find $bak_pathbak this system Will treat it as a variable name, not based on the above variable, and then append a bak. In fact, there are two ways to solve this problem. In the bak_path, don't add ”/” that is, bak_path=”/mnt/bak”.

and then cp $/etc/passwd $bak_path/Bak this way. The second is ${} to be said today. Bak_path=”/mnt/bak” The path is still this. The following cp $/etc/passwd ${bak_path}bak will do this.

The second scenario must be done in the shell to the result of a command. This time you need to use $()

For example: I want to kill a process, I want to close Drop pid for 1915 this tomcat

First I have to get this pid first. Ps -ef

Copyright © Windows knowledge All Rights Reserved