43559

What does mean $$ or $! in bash? [closed]

Question:

It's kind of easy question but I didn't find any information. What does mean $! or $$ in bash?

For example: ps -p $! or pstree $$?

Answer1:

Actually, these variables were inherited by bash from the Bourne shell.

"$$" means current PID.

"$!" is the PID of the last program your shell ran in the background (e.g. "myprog &")

Here is a list of shell variables:

<ul><li><a href="http://unixhelp.ed.ac.uk/scrpt/scrpt2.2.2.html" rel="nofollow">http://unixhelp.ed.ac.uk/scrpt/scrpt2.2.2.html</a></li> </ul>

Answer2:

<a href="http://tldp.org/LDP/abs/html/internalvariables.html#PIDVARREF" rel="nofollow">$!</a> is the process ID of the last job run in the background.

<a href="http://tldp.org/LDP/abs/html/special-chars.html#PROCESSIDREF" rel="nofollow">$$</a> is the process ID of the script itself.

(Both of the above are links to the <a href="http://tldp.org/LDP/abs/html/" rel="nofollow">Advanced Bash Scripting Guide</a> on TDLP.)

Recommend

  • Need example cordova-plugin-facebook4 for PhoneGap project
  • Boost linking on Linux with GCC
  • fprintf not writing to file [closed]
  • Same column of different files into the same new file
  • Convert a dict object to nested list
  • Run-time error in program compiled with MinGW gcc/g++ (nuwen distro)
  • PHP SimpleXML Group By Element Type
  • BeagleBone boot to Qt app with touch screen
  • SecurityException Permission Denial MediaProvider READ_EXTERNAL_STORAGE
  • How is user.dir configured for Tomcat servlets?
  • Errno 2 using python shutil.py No such file or directory for file destination
  • Is there a way to get the process ID of a console program I've just started in the background?
  • How to import Navit into Eclipse and use it in own android project
  • Find VMID for running instance
  • why calling cd shell command through system() or execvp() from a child process won't work?
  • Installing Perl6 and Panda on Ubuntu 15.10. Problems with bootstrap.pl
  • rewrite uppercase url to lowercase url htaccess
  • How can I get the full list of running processes on a Mac from a python app
  • Memory error in python- how to use more memory
  • Differences in dis-assembled C code of GCC and Borland?
  • Google Custom Search with transparent background
  • Spark fat jar to run multiple versions on YARN
  • Android fill_parent issue
  • Algorithm for a smudge tool?
  • Repeat a vertical line on every page in Report Builder / SSRS
  • Does CUDA 5 support STL or THRUST inside the device code?
  • How to apply VCL Styles to DLL-based forms in Inno Setup?
  • When should I choose bucket sort over other sorting algorithms?
  • How do you troubleshoot character encoding problems?
  • Rearranging Cells in UITableView Bug & Saving Changes
  • Circular dependency while pushing http interceptor
  • Use group_by to filter specific cases while keeping NAs
  • PHP: When would you need the self:: keyword?
  • Linker errors when using intrinsic function via function pointer
  • Acquiring multiple attributes from .xml file in c#
  • Understanding cpu registers
  • FormattedException instead of throw new Exception(string.Format(…)) in .NET
  • Checking variable from a different class in C#
  • reshape alternating columns in less time and using less memory
  • How can I use threading to 'tick' a timer to be accessed by other threads?