How to escape characters in a script_wrapper section?

I need to add the following alias line in my vnc script_wrapper configuration so that it will dynamically set a different GPU per session

      script_wrapper: |
        module purge
        export PATH="/opt/TurboVNC/bin:$PATH"
        export WEBSOCKIFY_CMD="/usr/bin/websockify"
        alias vglrun='/usr/bin/vglrun -d :0.$(( ${port:-0} % $(lspci | grep NVIDIA | wc -l)))'

this create issue when submitting the request “malformed format string - %$”
I’ve tried to escaped the $ and % by adding \ in front of them, but there is always an error "malformed format string - %"

How to escape these chars or how to be able to add $ and % chars ?

Thank you

use %% for a single % to display.

irb(main):019:0> sprintf("lias vglrun='/usr/bin/vglrun -d :0.$(( ${port:-0} % $(lspci | grep NVIDIA | wc -l)))'")
Traceback (most recent call last):
        5: from /home/jeff/apps/ruby/2.7.6/bin/irb:23:in `<main>'
        4: from /home/jeff/apps/ruby/2.7.6/bin/irb:23:in `load'
        3: from /home/jeff/apps/ruby/2.7.6/lib/ruby/gems/2.7.0/gems/irb-1.2.6/exe/irb:11:in `<top (required)>'
        2: from (irb):19
        1: from (irb):19:in `sprintf'
ArgumentError (malformed format string - %$)
irb(main):020:0> sprintf("lias vglrun='/usr/bin/vglrun -d :0.$(( ${port:-0} %% $(lspci | grep NVIDIA | wc -l)))'")
=> "lias vglrun='/usr/bin/vglrun -d :0.$(( ${port:-0} % $(lspci | grep NVIDIA | wc -l)))'"

Thank you, it works like a charm. But my alias is not set, so I will add this in /etc/profile.d

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.