2

If I am correct, pwd is a command, PWD is a variable('s name), and - in cd - is an operand.

What are the types of ~, ~-, ~+, * when they mean $HOME, the previous visited dir, the current dir, and the files under current dir? (from programming languages' perspective)

Are they variables' names? If yes, why does echo $~ not work?

Why does * work in:

for i in *; do ls "$i"; done
Gilles 'SO- stop being evil'
  • 807,993
  • 194
  • 1,674
  • 2,175
Tim
  • 98,580
  • 191
  • 570
  • 977
  • Please search the U&L site before asking such basic/fundamental Q's. Much of what you ask is covered throughout. For ex. tildes are discussed here: [Does ~ always equal $HOME](http://unix.stackexchange.com/questions/146671/does-always-equal-home).& here: [~ is $HOME, but sometimes?](http://unix.stackexchange.com/questions/34379/is-home-but-sometimes) & here: [What is the “~/” directory?](http://unix.stackexchange.com/questions/61768/what-is-the-directory) – slm Oct 11 '14 at 07:11
  • Also if you'd read the Bash manual there's an entire section devoted to tilde-prefixes, which is what these are called: [Bash Reference Manual - 3.5.2 Tilde Expansion](http://www.gnu.org/software/bash/manual/html_node/Tilde-Expansion.html) – slm Oct 11 '14 at 07:20

1 Answers1

1

* is a metacharacter (or wildcard), all the other ones are tilde-prefix examples (~ is standard, ~+ and ~- are extensions).

None are variables so there is no point prefixing them with a $.

echo $~ works fine, it displays $~. There is no expansion because ~ is not used as a prefix.

for i in *; ... works as designed.

jlliagre
  • 60,319
  • 10
  • 115
  • 157
  • 1
    Here they're discussed here in the Bash docs: http://www.gnu.org/software/bash/manual/html_node/Tilde-Expansion.html – slm Oct 11 '14 at 07:12