Klish 3 get full cmd line with params

12 views
Skip to first unread message

Aleksander Djuric

unread,
Jun 4, 2025, 4:00:15 AMJun 4
to klish
Hello! I here any other way to get full command line with all parameters in Klish 3?
Is there an environment variable in Klish 3 that contains such value? At now I can get the result only with bash.

Thanks in advance!

Serj Kalichev

unread,
Jun 4, 2025, 7:53:47 AMJun 4
to kl...@googlegroups.com
Hello.

Clarify your question. Klish 3 sets environment variables for all "script" actions. For bash and for any others.
Now there is no environment variable with whole line, just COMMAND and PARAMs separately. Do you need variable with whole line? Or you asked about getting command and parameters from non-"script" ACTION?
--
You received this message because you are subscribed to the Google Groups "klish" group.
To unsubscribe from this group and stop receiving emails from it, send an email to klish+un...@googlegroups.com.
To view this discussion visit https://groups.google.com/d/msgid/klish/a03ffce2-c8cc-4d7e-8656-b3c7436a0aaan%40googlegroups.com.


Message has been deleted

Aleksander Djuric

unread,
Jun 6, 2025, 3:54:34 AMJun 6
to klish
Hi Serj, Thanks for the quick reply!

For example, if I need to get the whole line of the comment and I don't want to use quotes, I should write a bash script like this:

        <PARAM name="comment" max="30" ptype="/DATA"/>
        <ACTION sym="script">
                n=0
                cmd="$KLISH_COMMAND"
                while [ $n -lt 30 ]; do
                        pn="KLISH_PARAM_comment_$n"
                        if [ -z ${!pn} ]; then break; fi
                        cmd+=" ${!pn}"
                        ((n++))
                done
                echo "$cmd"
        </ACTION>

In my opinion it would be great if KLISH_PARAM_comment and KLISH_PARAM_comment_0 did not return the same value.

среда, 4 июня 2025 г. в 14:53:47 UTC+3, Serj Kalichev:

Serj Kalichev

unread,
Jun 6, 2025, 4:05:01 AMJun 6
to kl...@googlegroups.com
Hi
I see
The previous klish2 has an environment variable with whole entered line. It can be something like:
KLISH_LINE="cmd_name comment1 comment2 another_param1"
I will reimplement this for klish 3

The KLISH_PARAM_comment containing the all values for this PARAM - it's interesting idea. Probably I will add it too.

But I'm not sure if I can do it quickly.

Serj Kalichev

unread,
Jun 11, 2025, 1:57:51 AMJun 11
to Aleksander Djuric, klish
Hi

The plans are to implement SELECT and REGEX string ptypes. The SELECT allows to enter one of the predefined words. The REGEX is regular expression.

ср, 11 июн. 2025 г., 00:28 Aleksander Djuric <aleksand...@gmail.com>:
Hi Serj!

Thank you very much for the quick solution and many thanks for your wonderful project!

I'm testing Klish 3 now and I see that the STRING type doesn't accept any parameters. Are there any plans to improve it? I guess it could accept a list of valid string variables, for example )

Have a nice day!



вт, 10 июн. 2025 г., 22:19 Serj Kalichev <serj.k...@gmail.com>:
Hi, Aleksander

I have implemented environment variable for whole line named KLISH_LINE.
The variables like KLISH_PARAM_comment now contain all values for multi-value parameters.It's not necessary to compose such string by hands.

Try it from klish 3 git repository https://klish.libcode.org. If all is ok I will probably release a new version.




04.06.2025 16:48, Aleksander Djuric пишет:

Serj Kalichev

unread,
Jun 11, 2025, 7:22:29 AMJun 11
to Aleksander Djuric, kl...@googlegroups.com
Hi

You can use single "print" or "printl" sym to print multi-line output.

  <COMMAND name="printl" help="ping">
    <ACTION sym="print">one
two
three</ACTION>
  </COMMAND>



What does it mean?

"*:0 one:1 two:2 three:3"
input transforming?



11.06.2025 11:49, Aleksander Djuric пишет:
Hi, Thanks!

It would be wonderful. I think it might look something like this:
<ACTION sym="STRING">one two three *</ACTION> or
<ACTION sym="STRING">*:0 one:1 two:2 three:3</ACTION>
Please look at some of the workarounds I use without these string types. It's real cases from my tests. Hope it can be helpful: 

1. String type for systemd time format (regex):

<PTYPE name="TIME" help="Time stamp">
        <COMPL>
                <ACTION sym="script">/usr/bin/date +%T</ACTION>
        </COMPL>
        <ACTION sym="script">[[ "$KLISH_VALUE" =~ ^([01][0-9]|2[0-3]):[0-5][0-9]:[0-5][0-9]$ ]]</ACTION>
</PTYPE>
 
2. String type for systemd date tokens (restricted set of values):

<PTYPE name="TOKEN" help="Special date token">
        <COMPL>
                <ACTION sym="printl">now</ACTION>
                <ACTION sym="printl">today</ACTION>
                <ACTION sym="printl">tomorrow</ACTION>
                <ACTION sym="printl">yesterday</ACTION>
        </COMPL>
        <ACTION sym="script" exec_on="fail">[[ "$KLISH_VALUE" =~ ^(now|today|tomorrow|yesterday)$ ]]</ACTION>
</PTYPE>

3. Journald message priority (restricted set of values with replacement)

<PTYPE name="PRIORITY" help="Message priority">
        <COMPL>
                <ACTION sym="printl">emergency</ACTION>
                <ACTION sym="printl">alerts</ACTION>
                <ACTION sym="printl">critical</ACTION>
                <ACTION sym="printl">errors</ACTION>
                <ACTION sym="printl">warning</ACTION>
                <ACTION sym="printl">notice</ACTION>
                <ACTION sym="printl">info</ACTION>
                <ACTION sym="printl">debug</ACTION>
        </COMPL>
        <ACTION sym="script">
        case "$KLISH_VALUE" in
                emergency )     echo -n 0 ;;
                alerts )        echo -n 1 ;;
                critical )      echo -n 2 ;;
                errors )        echo -n 3 ;;
                warning )       echo -n 4 ;;
                notice )        echo -n 5 ;;
                info )          echo -n 6 ;;
                debug )         echo -n 7 ;;
                * )     return 1 ;;
        esac
        </ACTION>
</PTYPE>

Regards,

ср, 11 июн. 2025 г. в 08:57, Serj Kalichev <serj.k...@gmail.com>:
Reply all
Reply to author
Forward
0 new messages