bug-bash
[Top][All Lists]
Advanced

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

Fwd: compgen -W [wordlist] will do command subtitution and parameter exp


From: Koichi Murase
Subject: Fwd: compgen -W [wordlist] will do command subtitution and parameter expansion in wordlist
Date: Fri, 4 Mar 2022 00:04:56 +0900

Basically, you can reply to the bug-bash list instead of directly
replying to the individuals.

2022年3月3日(木) 23:32 ladyrick <ladyrick@qq.com>:
> Thank you for you reply.
>
> But your example still doesn't work.
>
> compgen -W '$(fc -l -10)'
> of course passed the literal '$(fc -l -10)' to compgen. But inside compgen, 
> it is again subtituted. prove:
> ![image](66DE9003@7E85D46F.87D12062.jpg)

It depends on what would be the result that you expect.

a) If you expect the words obtained from the expanded result of $(fc
-l -10), the first picture you have attached in the previous reply [I
attach it again for bug-bash list: 66DE9003@7E85D46F.87D12062.jpg] is
the expected one. In this case, we can just pass the literal $(fc -l
-10) to compgen as I have replied.

b) If you expect the lines obtained from the expanded result of $(fc
-l -10), you need to set IFS=$'\n'. So,

        IFS=$'\n' compgen -W '$(fc -l -10)'

> If i really need the literal '$(fc -l -1)', for example I want to get '$(fc' 
> when I type '$(f<tab>'
> I need to do this:
> ![image](302F8FB8@DA9AED36.87D12062.jpg)

c) If you expect the literal $(fc -l -1), you need to quote the word as

        compgen -W '\$\(fc\ -l\ -1\)'

or

        compgen -W \''$(fc -l -1)'\'

or

        tmp='$(fc -l -1)'
        compgen -W '"$tmp"'

What is the result you actually would like to achieve?

--
Koichi

Attachment: 66DE9003@7E85D46F.87D12062.jpg
Description: JPEG image

Attachment: 302F8FB8@DA9AED36.87D12062.jpg
Description: JPEG image


reply via email to

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