Reputation: 61
I was playing around with the touch
command and as I entered the touch ()
command, I expected either an error or a new empty file named ()
.
Instead, I got this
touch ()
>
and it expects me to enter something.
What is this touch ()
command doing? What is it for?
Upvotes: 1
Views: 305
Reputation: 8406
This question is a bit of an illusion, based on a confusion between types of commands -- some commands are keywords built in to the shell, (like for
and if
), some are aliases, (like ls
and ll
and l
on most distros), some are functions, but most are executables.
While there is a touch
command, (in Ubuntu it activates the executable /usr/bin/touch
), the code touch ()
never goes near it.
As iBug's answer notes, the ()
tells the shell that a function is being defined, but since there's no code, the shell prompts the user to enter some.
This isn't specific to the touch
command however. The shell will do the same with any command, whether real:
bash ()
less ()
Or made up:
foobarbaz()
There are exceptions. For example, if the command is an alias, like ls
, this happens:
ls ()
bash: syntax error near unexpected token `('
Upvotes: 1
Reputation: 37287
With touch ()
, your shell is expecting you to define a function, something like this:
touch () {
echo "Hello"
}
(don't do that)
Since ()
are shell metacharacters, if you want to create files with such names, escape them or put them in quotes:
touch \(\)
touch '()'
touch "()"
Upvotes: 3