Quantcast
Channel: UNIX and Linux Forums
Viewing all articles
Browse latest Browse all 16232

[awk] printing value of a variable assignment from a file

$
0
0
Heyas

Me try to print only the value of a (specific) variable assignment from a file.

What i get (1):
Code:

:) tui $ bin/tui-conf-get ~/.tui_rc TUI_THEME

dot-blue
""
"$TUI_DIR_INSTALL_ROOT/usr"
"$TUI_DIR_INSTALL_ROOT/etc/tui"
"$TUI_PREFIX/share/doc/tui"
"$TUI_PREFIX/share/tui"
"/home/sea/.config/tui"
"$TUI_DIR_USER/logs"
"$TUI_DIR_SYSTEM/themes"
"/home/sea/.cache"
"/home/sea/.local/bin"
"/home/sea/.local/man/man1"
"/home/sea/.cache/tui.tmp~"
"$TUI_DIR_USER/loadlist.conf"
"$TUI_DIR_USER/apps.conf"
"$TUI_DIR_USER/user.conf"
"$TUI_DIR_USER/settings.conf"
"$TUI_DIR_CONF/tui.conf"

What i want: (2)
Code:

✔ tui $ bin/tui-conf-get ~/.tui_rc TUI_THEME

dot-blue

Code i got:
Code:

CONFILE="$1"
VARNAME="$2"
awk        ' 
                /^#/  ||
                /^\[/  ||
                /!VAR/ { next }
                {
                        if (VAR = $1) {
                                if ("-z" != $2) {
                                        print $2
                                }
                        }
        }' VAR="$VARNAME" FS="=" "$CONFFILE"


The RC file looks like:
Code:

#/home/sea/.tui_rc
# This file is not ment to be changed manualy!
# Any change of this file may result in an unusable TUI.
# Do changes at your own risk!
#
#        Theme
#        Options are:        default, default-red, dot-blue, dot-red, \
#                        floating, mono, witch-purple, witch-yellow
#        See /usr/share/tui/themes
#
        TUI_THEME=dot-blue
#
#        Paths
#
[ -z "$TUI_DIR_INSTALL_ROOT" ] &&  \
        TUI_DIR_INSTALL_ROOT=""
[ -z "$TUI_PREFIX" ] && \
        TUI_PREFIX="$TUI_DIR_INSTALL_ROOT/usr"
[ -z "$TUI_DIR_CONF" ] && readonly \
        ...
#
#        Files
#
[ -z "$TUI_FILE_TEMP" ] && readonly \
        TUI_FILE_TEMP="/home/sea/.cache/tui.tmp~"
[ -z "$TUI_FILE_CONF_LOADLIST" ] && readonly \
        TUI_FILE_CONF_LOADLIST="$TUI_DIR_USER/loadlist.conf"
...

What am i missing?
Tia

Viewing all articles
Browse latest Browse all 16232

Latest Images

Trending Articles



Latest Images