0

Bash: Single Line Expressions

Create and open file (only type filename once)

Certain I've seen this done but can't work it out.

touch filename ; open filename

How can I do this but only type the filename in once?

Edit: I found a solution!

touch filename ; start $_
HotSauceCoconuts
  • 301
  • 5
  • 19
  • I suggest to use a function. See `help function`. – Cyrus May 20 '22 at 19:52
  • 1
    Stack Overflow is only for practical, answerable questions about writing software. Questions about interactive command-line shortcuts are better suited to [unix.se] or [Super User](https://superuser.com/), as compromising readability and maintainability in pursuit of one-liners is not good practice when writing software that's going to need to be maintained over time (and many of the shortcuts in the shell that could be used for this purpose, like history expansion, are optional interactive extensions not guaranteed to be available during script execution). – Charles Duffy May 20 '22 at 20:00
  • 2
    Depends on which `open` command you are talking about. – chepner May 20 '22 at 20:12

1 Answers1

0

I discovered what i was looking for: $_

Example:

touch filename ; start $_

HotSauceCoconuts
  • 301
  • 5
  • 19