Skip to main content
added 181 characters in body
Source Link
Stephen Harris
  • 49.3k
  • 7
  • 115
  • 138

The variable $_ is the last argument of the previous line you typed. So, for example, cd $_ would do what you described

bash-4.2$ ls X
1
bash-4.2$ cd $_
bash-4.2$ ls
1

There's also some command substitution options as well; eg ^ will replace commands on the previous line

bash-4.2$ ls X
1
bash-4.2$ ^ls^cd
cd X
bash-4.2$ ls
1

The variable $_ is the last argument of the previous line you typed. So, for example, cd $_ would do what you described

bash-4.2$ ls X
1
bash-4.2$ cd $_
bash-4.2$ ls
1

The variable $_ is the last argument of the previous line you typed. So, for example, cd $_ would do what you described

bash-4.2$ ls X
1
bash-4.2$ cd $_
bash-4.2$ ls
1

There's also some command substitution options as well; eg ^ will replace commands on the previous line

bash-4.2$ ls X
1
bash-4.2$ ^ls^cd
cd X
bash-4.2$ ls
1
Source Link
Stephen Harris
  • 49.3k
  • 7
  • 115
  • 138

The variable $_ is the last argument of the previous line you typed. So, for example, cd $_ would do what you described

bash-4.2$ ls X
1
bash-4.2$ cd $_
bash-4.2$ ls
1