Saw the use of !$
on this site, so I made a short bash script "bang_dollar.sh
" as below:
#!/bin/bash
echo -e '\n'
touch touche.txt
vi !$
This was a copy verbatim of what someone posted as a solution on this site (to a different question).
I ran
$ touch touche.txt
$ vi !$
from the command line, and vi does in fact open touche.txt
for editing.
My bang_dollar.sh script however, creates a file named "touche.txt", and vi opens,
but "!$
" is literally interpreted as !$
, so vi opens a file for editing named "!$
".
Is it possible to use "!$
" in a bash script with some sort of masking? And shouldn't a file named "!$
" be illegal on BASH 5.1.4?
file=touche.txt; vi "$file"
. But you do you. – ilkkachu Aug 30 '23 at 20:16