Sample Header Ad - 728x90

How to store and print variables with special characters in shell/bash/sh/

0 votes
2 answers
7578 views
I basically need to load, save and reload multiple times and in different forms a variable that contains arguments for a program. The problem is that this variable can't be treated as a usual variable because it contains the "-" sign in the start. And print it or load it to be possible to see what it contains makes things hard due to the constant need of a \\ at the start before it can be used or not. A trick was always saved it with the \\, but before reading it, I echo $it then read the last output as a variable for the use case. This is strongly impractical, so I need a way to save the contents of a variable in a manner that will never interfere with the code that executes it. The below variable is used by yad a default for gdb, but it can be for any other program. For example, a quick test to know if a variable like that can be used in my context is trough printf **WITHOUT** the need of any printf parameter. This is because: gdbParameters="-ex 'set pagination off' -ex 'set environment G_MESSAGES_DEBUG = all'" printf $gdbParameters returns: printf: usage: printf [-v var] format [arguments] Thank you all.
Asked by DATALOT (459 rep)
Jun 20, 2020, 05:08 PM
Last activity: Mar 6, 2025, 03:51 PM