help-bash
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: ls head and gv


From: Lawrence Velázquez
Subject: Re: ls head and gv
Date: Fri, 28 Jul 2023 23:59:05 -0400
User-agent: Cyrus-JMAP/3.9.0-alpha0-592-ga9d4a09b4b-fm-defalarms-20230725.001-ga9d4a09b

On Fri, Jul 28, 2023, at 11:11 PM, David Niklas wrote:
> I used this command:
> alias lgv="gv "$(ls -c *.pdf | head -n1)" &"
>
> What I expected was the latest pdf document to be brought up in gv and gv
> goes to the background.
> What happens is that a semi-random pdf document is loaded into gv and gv
> goes into the background.
>
> Any ideas?

The command substitution is being evaluated when the alias is
defined, not when it is run.

        bash-5.2$ alias foo="echo foo "$(date)" bar"
        bash-5.2$ alias foo
        alias foo='echo foo Fri Jul 28 23:49:59 EDT 2023 bar'

The quickest "solution" is to fix your quoting.

        bash-5.2$ alias foo='echo foo "$(date)" bar'
        bash-5.2$ alias foo
        alias foo='echo foo "$(date)" bar'

Even if you do this, your chosen method of finding the most recently
modified file is fragile.  Consider using something more robust.

https://mywiki.wooledge.org/BashFAQ/003

-- 
vq



reply via email to

[Prev in Thread] Current Thread [Next in Thread]