KSH styling text based menu using STDERR












4















Is it possible to format the STDERR in order to have a better looking menu using the select command?



I have a simple select



    select oChoice in $(<tempMenu.menu) ; do  
case "$oChoice" in
*)
break
;;
esac
done


I've tried a trick like:



    exec 3>&1
select ...
...
done 2>&1 1>&3 | sed 's/^/NICE OUTPUT /'


But I cannot use escape sequences (i.e. colors), for example



   ...
done 22>&1 1>&3 | sed 's/^/33[1;33m33[44mNICE OUTPUT /'
or
done 22>&1 1>&3 | sed 's/^/\033[1;33m\033[44mNICE OUTPUT /'


The escape sequences are not escaped and also the STDOUT is altered because I have customized the PS3 as well.



PS3="$(print \n\r)# $(print "\033[1;33m\033[44m")"$QUESTION"$(print "\033[0m\033[1;1m\033[44m") `tput sc` $(print "")
#$(print "")
# $(print "")
# Status: $status $(print "")
# $(print "")
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ `tput rc` "


As far as I understand (Show only stderr on screen but write both stdout and stderr to file) I cannot separate the STDERR from the STDOUT, so, is there a smarter way to create dynamic text-based menus just using the STDOUT? (or an otherway to workaround my issue)










share|improve this question
















bumped to the homepage by Community 13 mins ago


This question has answers that may be good or bad; the system has marked it active so that they can be reviewed.











  • 1





    consider editing your post to include the contents of tempMenu.menu. Hard to tell what your problem is without seeing what the inputs are. Good luck.

    – shellter
    May 18 '12 at 17:37











  • Thanks @shellter , I've found a solution using dialog instead of select. I'll update the question, or answer myself (not sure what is better to do) as soon as I'll have time to do it.

    – tmow
    May 22 '12 at 14:19
















4















Is it possible to format the STDERR in order to have a better looking menu using the select command?



I have a simple select



    select oChoice in $(<tempMenu.menu) ; do  
case "$oChoice" in
*)
break
;;
esac
done


I've tried a trick like:



    exec 3>&1
select ...
...
done 2>&1 1>&3 | sed 's/^/NICE OUTPUT /'


But I cannot use escape sequences (i.e. colors), for example



   ...
done 22>&1 1>&3 | sed 's/^/33[1;33m33[44mNICE OUTPUT /'
or
done 22>&1 1>&3 | sed 's/^/\033[1;33m\033[44mNICE OUTPUT /'


The escape sequences are not escaped and also the STDOUT is altered because I have customized the PS3 as well.



PS3="$(print \n\r)# $(print "\033[1;33m\033[44m")"$QUESTION"$(print "\033[0m\033[1;1m\033[44m") `tput sc` $(print "")
#$(print "")
# $(print "")
# Status: $status $(print "")
# $(print "")
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ `tput rc` "


As far as I understand (Show only stderr on screen but write both stdout and stderr to file) I cannot separate the STDERR from the STDOUT, so, is there a smarter way to create dynamic text-based menus just using the STDOUT? (or an otherway to workaround my issue)










share|improve this question
















bumped to the homepage by Community 13 mins ago


This question has answers that may be good or bad; the system has marked it active so that they can be reviewed.











  • 1





    consider editing your post to include the contents of tempMenu.menu. Hard to tell what your problem is without seeing what the inputs are. Good luck.

    – shellter
    May 18 '12 at 17:37











  • Thanks @shellter , I've found a solution using dialog instead of select. I'll update the question, or answer myself (not sure what is better to do) as soon as I'll have time to do it.

    – tmow
    May 22 '12 at 14:19














4












4








4








Is it possible to format the STDERR in order to have a better looking menu using the select command?



I have a simple select



    select oChoice in $(<tempMenu.menu) ; do  
case "$oChoice" in
*)
break
;;
esac
done


I've tried a trick like:



    exec 3>&1
select ...
...
done 2>&1 1>&3 | sed 's/^/NICE OUTPUT /'


But I cannot use escape sequences (i.e. colors), for example



   ...
done 22>&1 1>&3 | sed 's/^/33[1;33m33[44mNICE OUTPUT /'
or
done 22>&1 1>&3 | sed 's/^/\033[1;33m\033[44mNICE OUTPUT /'


The escape sequences are not escaped and also the STDOUT is altered because I have customized the PS3 as well.



PS3="$(print \n\r)# $(print "\033[1;33m\033[44m")"$QUESTION"$(print "\033[0m\033[1;1m\033[44m") `tput sc` $(print "")
#$(print "")
# $(print "")
# Status: $status $(print "")
# $(print "")
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ `tput rc` "


As far as I understand (Show only stderr on screen but write both stdout and stderr to file) I cannot separate the STDERR from the STDOUT, so, is there a smarter way to create dynamic text-based menus just using the STDOUT? (or an otherway to workaround my issue)










share|improve this question
















Is it possible to format the STDERR in order to have a better looking menu using the select command?



I have a simple select



    select oChoice in $(<tempMenu.menu) ; do  
case "$oChoice" in
*)
break
;;
esac
done


I've tried a trick like:



    exec 3>&1
select ...
...
done 2>&1 1>&3 | sed 's/^/NICE OUTPUT /'


But I cannot use escape sequences (i.e. colors), for example



   ...
done 22>&1 1>&3 | sed 's/^/33[1;33m33[44mNICE OUTPUT /'
or
done 22>&1 1>&3 | sed 's/^/\033[1;33m\033[44mNICE OUTPUT /'


The escape sequences are not escaped and also the STDOUT is altered because I have customized the PS3 as well.



PS3="$(print \n\r)# $(print "\033[1;33m\033[44m")"$QUESTION"$(print "\033[0m\033[1;1m\033[44m") `tput sc` $(print "")
#$(print "")
# $(print "")
# Status: $status $(print "")
# $(print "")
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ `tput rc` "


As far as I understand (Show only stderr on screen but write both stdout and stderr to file) I cannot separate the STDERR from the STDOUT, so, is there a smarter way to create dynamic text-based menus just using the STDOUT? (or an otherway to workaround my issue)







bash shell shell-script io-redirection ksh






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Apr 13 '17 at 12:36









Community

1




1










asked May 9 '12 at 7:10









tmowtmow

1,1031017




1,1031017





bumped to the homepage by Community 13 mins ago


This question has answers that may be good or bad; the system has marked it active so that they can be reviewed.







bumped to the homepage by Community 13 mins ago


This question has answers that may be good or bad; the system has marked it active so that they can be reviewed.










  • 1





    consider editing your post to include the contents of tempMenu.menu. Hard to tell what your problem is without seeing what the inputs are. Good luck.

    – shellter
    May 18 '12 at 17:37











  • Thanks @shellter , I've found a solution using dialog instead of select. I'll update the question, or answer myself (not sure what is better to do) as soon as I'll have time to do it.

    – tmow
    May 22 '12 at 14:19














  • 1





    consider editing your post to include the contents of tempMenu.menu. Hard to tell what your problem is without seeing what the inputs are. Good luck.

    – shellter
    May 18 '12 at 17:37











  • Thanks @shellter , I've found a solution using dialog instead of select. I'll update the question, or answer myself (not sure what is better to do) as soon as I'll have time to do it.

    – tmow
    May 22 '12 at 14:19








1




1





consider editing your post to include the contents of tempMenu.menu. Hard to tell what your problem is without seeing what the inputs are. Good luck.

– shellter
May 18 '12 at 17:37





consider editing your post to include the contents of tempMenu.menu. Hard to tell what your problem is without seeing what the inputs are. Good luck.

– shellter
May 18 '12 at 17:37













Thanks @shellter , I've found a solution using dialog instead of select. I'll update the question, or answer myself (not sure what is better to do) as soon as I'll have time to do it.

– tmow
May 22 '12 at 14:19





Thanks @shellter , I've found a solution using dialog instead of select. I'll update the question, or answer myself (not sure what is better to do) as soon as I'll have time to do it.

– tmow
May 22 '12 at 14:19










1 Answer
1






active

oldest

votes


















0














Another way is avoiding the select and make a menu.
Make a shell script for each menu choice (action1.sh, xxx.sh and passwords.sh),
configure them in menu.cfg:



1 action1 Do action 1
2 xxx Another nice item for you
3 passwords Very dangerous


And start a menu with a script that reads menu.cfg



#!/bin/ksh
formatmenu()
{
if [ $# -eq 2 ]
then
printf "%d) %sn" ${1} "$2"
else
printf " %sn" "${1}"
fi
}
showMenu()
{
echo "Enter 0 to stop or choose beneath."
cat menu.cfg|while read option proces description
do
formatmenu ${option} ${proces}
formatmenu "${description}"
done
}

getAction()
{
showMenu
while [ ${CHOICE} -eq -1 ]
do
read CHOICE?"Please enter a digit: "
if [[ ${CHOICE} != +([0-9]) ]]
then
CHOICE=-1
echo "Invalid, please enter a digit."
fi
done
}

performAction()
{
if [ ${CHOICE} -eq 0 ]
then
return
fi
process=$(grep "^${CHOICE} " menu.cfg | cut -d -f2)


echo "===${process}.sh==="
. ${process}.sh
}

# Start

export CHOICE=-1
getAction
echo choice=${CHOICE}
performAction
exit 0





share|improve this answer























    Your Answer








    StackExchange.ready(function() {
    var channelOptions = {
    tags: "".split(" "),
    id: "106"
    };
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function() {
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled) {
    StackExchange.using("snippets", function() {
    createEditor();
    });
    }
    else {
    createEditor();
    }
    });

    function createEditor() {
    StackExchange.prepareEditor({
    heartbeatType: 'answer',
    autoActivateHeartbeat: false,
    convertImagesToLinks: false,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: null,
    bindNavPrevention: true,
    postfix: "",
    imageUploader: {
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    },
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    });


    }
    });














    draft saved

    draft discarded


















    StackExchange.ready(
    function () {
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f38200%2fksh-styling-text-based-menu-using-stderr%23new-answer', 'question_page');
    }
    );

    Post as a guest















    Required, but never shown

























    1 Answer
    1






    active

    oldest

    votes








    1 Answer
    1






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    0














    Another way is avoiding the select and make a menu.
    Make a shell script for each menu choice (action1.sh, xxx.sh and passwords.sh),
    configure them in menu.cfg:



    1 action1 Do action 1
    2 xxx Another nice item for you
    3 passwords Very dangerous


    And start a menu with a script that reads menu.cfg



    #!/bin/ksh
    formatmenu()
    {
    if [ $# -eq 2 ]
    then
    printf "%d) %sn" ${1} "$2"
    else
    printf " %sn" "${1}"
    fi
    }
    showMenu()
    {
    echo "Enter 0 to stop or choose beneath."
    cat menu.cfg|while read option proces description
    do
    formatmenu ${option} ${proces}
    formatmenu "${description}"
    done
    }

    getAction()
    {
    showMenu
    while [ ${CHOICE} -eq -1 ]
    do
    read CHOICE?"Please enter a digit: "
    if [[ ${CHOICE} != +([0-9]) ]]
    then
    CHOICE=-1
    echo "Invalid, please enter a digit."
    fi
    done
    }

    performAction()
    {
    if [ ${CHOICE} -eq 0 ]
    then
    return
    fi
    process=$(grep "^${CHOICE} " menu.cfg | cut -d -f2)


    echo "===${process}.sh==="
    . ${process}.sh
    }

    # Start

    export CHOICE=-1
    getAction
    echo choice=${CHOICE}
    performAction
    exit 0





    share|improve this answer




























      0














      Another way is avoiding the select and make a menu.
      Make a shell script for each menu choice (action1.sh, xxx.sh and passwords.sh),
      configure them in menu.cfg:



      1 action1 Do action 1
      2 xxx Another nice item for you
      3 passwords Very dangerous


      And start a menu with a script that reads menu.cfg



      #!/bin/ksh
      formatmenu()
      {
      if [ $# -eq 2 ]
      then
      printf "%d) %sn" ${1} "$2"
      else
      printf " %sn" "${1}"
      fi
      }
      showMenu()
      {
      echo "Enter 0 to stop or choose beneath."
      cat menu.cfg|while read option proces description
      do
      formatmenu ${option} ${proces}
      formatmenu "${description}"
      done
      }

      getAction()
      {
      showMenu
      while [ ${CHOICE} -eq -1 ]
      do
      read CHOICE?"Please enter a digit: "
      if [[ ${CHOICE} != +([0-9]) ]]
      then
      CHOICE=-1
      echo "Invalid, please enter a digit."
      fi
      done
      }

      performAction()
      {
      if [ ${CHOICE} -eq 0 ]
      then
      return
      fi
      process=$(grep "^${CHOICE} " menu.cfg | cut -d -f2)


      echo "===${process}.sh==="
      . ${process}.sh
      }

      # Start

      export CHOICE=-1
      getAction
      echo choice=${CHOICE}
      performAction
      exit 0





      share|improve this answer


























        0












        0








        0







        Another way is avoiding the select and make a menu.
        Make a shell script for each menu choice (action1.sh, xxx.sh and passwords.sh),
        configure them in menu.cfg:



        1 action1 Do action 1
        2 xxx Another nice item for you
        3 passwords Very dangerous


        And start a menu with a script that reads menu.cfg



        #!/bin/ksh
        formatmenu()
        {
        if [ $# -eq 2 ]
        then
        printf "%d) %sn" ${1} "$2"
        else
        printf " %sn" "${1}"
        fi
        }
        showMenu()
        {
        echo "Enter 0 to stop or choose beneath."
        cat menu.cfg|while read option proces description
        do
        formatmenu ${option} ${proces}
        formatmenu "${description}"
        done
        }

        getAction()
        {
        showMenu
        while [ ${CHOICE} -eq -1 ]
        do
        read CHOICE?"Please enter a digit: "
        if [[ ${CHOICE} != +([0-9]) ]]
        then
        CHOICE=-1
        echo "Invalid, please enter a digit."
        fi
        done
        }

        performAction()
        {
        if [ ${CHOICE} -eq 0 ]
        then
        return
        fi
        process=$(grep "^${CHOICE} " menu.cfg | cut -d -f2)


        echo "===${process}.sh==="
        . ${process}.sh
        }

        # Start

        export CHOICE=-1
        getAction
        echo choice=${CHOICE}
        performAction
        exit 0





        share|improve this answer













        Another way is avoiding the select and make a menu.
        Make a shell script for each menu choice (action1.sh, xxx.sh and passwords.sh),
        configure them in menu.cfg:



        1 action1 Do action 1
        2 xxx Another nice item for you
        3 passwords Very dangerous


        And start a menu with a script that reads menu.cfg



        #!/bin/ksh
        formatmenu()
        {
        if [ $# -eq 2 ]
        then
        printf "%d) %sn" ${1} "$2"
        else
        printf " %sn" "${1}"
        fi
        }
        showMenu()
        {
        echo "Enter 0 to stop or choose beneath."
        cat menu.cfg|while read option proces description
        do
        formatmenu ${option} ${proces}
        formatmenu "${description}"
        done
        }

        getAction()
        {
        showMenu
        while [ ${CHOICE} -eq -1 ]
        do
        read CHOICE?"Please enter a digit: "
        if [[ ${CHOICE} != +([0-9]) ]]
        then
        CHOICE=-1
        echo "Invalid, please enter a digit."
        fi
        done
        }

        performAction()
        {
        if [ ${CHOICE} -eq 0 ]
        then
        return
        fi
        process=$(grep "^${CHOICE} " menu.cfg | cut -d -f2)


        echo "===${process}.sh==="
        . ${process}.sh
        }

        # Start

        export CHOICE=-1
        getAction
        echo choice=${CHOICE}
        performAction
        exit 0






        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Feb 16 '14 at 3:19









        Walter AWalter A

        50429




        50429






























            draft saved

            draft discarded




















































            Thanks for contributing an answer to Unix & Linux Stack Exchange!


            • Please be sure to answer the question. Provide details and share your research!

            But avoid



            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.


            To learn more, see our tips on writing great answers.




            draft saved


            draft discarded














            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f38200%2fksh-styling-text-based-menu-using-stderr%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown





















































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown

































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown







            Popular posts from this blog

            Accessing regular linux commands in Huawei's Dopra Linux

            Can't connect RFCOMM socket: Host is down

            Kernel panic - not syncing: Fatal Exception in Interrupt