RECOMMENDED: Click here to fix Windows errors and optimize system performance

How to Use the xmessage App Inside of Shell Scripts

If you’ve spent any significant amount of time writing scripts for the Bash or tcsh environments, then you’ve more than likely used the echo command to pass data to the user. This command can echo environment variables as well as messages, but there’s an alternative if you’re merely trying to send a message over to the user if you were writing, say, an install script. This alternative allows your message to appear in a window, which is significantly more user friendly. It also should appear more modern in many circumstances.

Technically the xmessage command could additionally be used to transmit environment variables to the user. The syntax is identical to echo, so if you’re already used to using this command then you should have no additional difficulties using xmessage in its place.

Method 1: Usage of the xmessage Command in Place of Echo

While you could use these commands from a run dialog box opened by holding down the Windows key and pushing R or even the CLI prompt, they’re most useful from inside of a script. Say you wanted to pause an installation script and prompt the user for input. Add this line to your script:

xmessage Tap the okay button to continue.

When your script executes, you’ll generate a dialog box for the user.

xmessagea

The command could also be used to echo an environment variable during the execution of any type of script. Take for example if you had wanted to display the code used by the user’s current prompt. The command xmessage $PS1 generates output based on this, though it would only work if the user executed this from a terminal window or allowed their file manager to do so.

PRO TIP: If the issue is with your computer or a laptop/notebook you should try using the Reimage Plus Software which can scan the repositories and replace corrupt and missing files. This works in most cases, where the issue is originated due to a system corruption. You can download Reimage Plus by Clicking Here

xmessageb

Method 2: Creating Buttons with xmessage

Script programmers can use xmessage to create buttons for the user to select. Considering the following line:

xmessage “Can anybody hear me?” -buttons yes,no

xmessagec

Text to appear in the box got enclosed in quotes. The tack buttons command then features comma delimited button labels after it. Exit values equal 100 plus the number of the button tapped, so it’s possible to find out which one the user selected. You could create extra buttons beyond the basic two just like this:

xmessage “Remember this prompt?” -buttons Abort,Retry,Fail

xmessaged

It makes writing Bash and tcsh scripts easier for those who don’t want to work with a terminal.

PRO TIP: If the issue is with your computer or a laptop/notebook you should try using the Reimage Plus Software which can scan the repositories and replace corrupt and missing files. This works in most cases, where the issue is originated due to a system corruption. You can download Reimage Plus by Clicking Here
RECOMMENDED: Click here to fix Windows errors and optimize system performance

About Kevin Arrows

Hi! I'm Kevin. Thank you for reading the article above. I am a certified MCTS (Microsoft Certified Technology Specialist) with over 10 years of experience. I love to address tech issues, and write tech how-to's in a way that it can be followed by everyone.