1

Why doesn't the following work?

function xyz(){ touch $1; }
xyz temp1.txt

I get an error

touch: missing file operand
Try `touch --help' for more information.

closed as off-topic by DopeGhoti, Jeff Schaller, mosvy, steeldriver, GAD3R Jan 8 at 20:25

This question appears to be off-topic. The users who voted to close gave this specific reason:

  • "Questions describing a problem that can't be reproduced and seemingly went away on its own (or went away when a typo was fixed) are off-topic as they are unlikely to help future readers." – DopeGhoti, mosvy, steeldriver, GAD3R
If this question can be reworded to fit the rules in the help center, please edit the question.

  • Welcome to Unix&Linux at StackExchange! I just tried your two exact commands on bash and it worked for me... Can you double check your setup? Try type xyz to see what bash thinks the definition of your function is... – filbranden Jan 8 at 18:46
  • 1
    Did you perhaps run something more interesting, like xyz "file name with spaces"? – Jeff Schaller Jan 8 at 19:08
  • Sorry! It worked fine. Thank you for quick (and kind) responses. – user330468 Jan 8 at 20:00
0

Unable to replicate:

$ function xyz() { touch "$1"; }
$ xyz temp1.txt
$ ls temp1.txt
temp1.txt

Not the answer you're looking for? Browse other questions tagged or ask your own question.