Press any key to continue

Page 1 of 1 RSS Feed - Follow comments on this article (Bash - Press Any Key) with your RSS reader." target="_blank">
*

Related Articles - Jump straight to an overview of related articles (if any) ..."> Comments - Give us your opinion, & read opinions of others ... - So far we have 4 comments."> 4

In this article I’ll describe what I have used to create a “Press Any Key to Continue” in a Bash script (Linux/MacOS X).

Bạn đang xem: Press any key to continue

Working with scripts in Bash (Terminal or Shell) isn’t what I vày daily. The day I had khổng lồ create a script khổng lồ help me vày an Sđất nước hình chữ S update followed by a massive sầu recompile. I wanted khổng lồ see the Sđất nước hình chữ S result first before proceeding with recompile, so I had to add a “Press Any Key To Continue” option in the script.

Since it took me a little effort, I figured; let’s describe this in an article. After all, it may be good reference for myself và for others.These methods work for Linux và MacOS.


Twitter - Share this page ..."> Facebook - Share this page ..."> Pinterest - Share this page ..."> Digg - Share this page ..."> Reddit - Share this page ..."> StumbleUpon - Share this page ..." style="margin-right:10px;"> eMail - eMail this page to lớn friends ..."> Print - Print this page ..." style="margin-right:10px;"> Share this page at ... - Additional Services!" style="margin-right:4px;"> Sharing this page - This page has been shared this many times">
Ad Blocking Detected

Please consider disabling your ad blocker for our website.We rely on these ads khổng lồ be able khổng lồ run our trang web.You can of course support us in other ways (see Support Us on the left).


Bash Press Key lớn continue

In certain situations, one may want a “Press any key khổng lồ continue” option in a script, lớn give the user some time khổng lồ Review certain output of the script. For example, I made a script which does an SViệt Nam update of Lazarus Pascal, and then does a full clean “make”. Before the “make” starts, I’d like to đánh giá what was updated from Stoàn nước, just lớn give sầu me an idea what to lớn expect once the compiler and linker are done creating a new version of Lazarus Pascal. Obviously, you can apply this to lớn your own script which may or may not be related lớn anything Lazarus Pascal.

For this we use the “read” comm& (man page), which is available under Linux & MacOS X. The man page under MacOS X is somewhat limited, not sure why, so I recommkết thúc looking at the links.

The simplest way, that I found, lớn accomplish this is:


cảnh báo that this catches all keys except keys like Shift, Alt, Ctrl, Windows, Alt-menu, & Commvà (  ). You could consider this a problem … or not.

ParametersParameterPurpose
-n 1Return after typing one character (và that’s why Alt, Shift and such vị not work – as they are not characters).
-rDo not allow backslashes to escape characters (this way a backslash will work as well)
-sDo not emang lại (display) what is being typed.
-p $”Press any key lớn continue\n”Display a prompt saying “Press any key to lớn continue” (\n = new line).Dollar symbol ($) must be before the quoted string khổng lồ allow escape characters like new line.

Ad Blocking Detected

Please consider disabling your ad blocker for our website.We rely on these ads to be able lớn run our trang web.You can of course support us in other ways (see Support Us on the left).

Xem thêm: Review Sữa Rửa Mặt Perfect White Clay, Sữa Rửa Mặt Đất Sét Trắng Perfect White Senka


Adding a Time Out

We can expand this line with a time out. So if the user does not press any key within an x amount of seconds (5 seconds in the example below), the script will continue as if the user had pressed a key. This is done as such:


The parameter “-t 5 ” sets the timeout khổng lồ 5 seconds – which you can alter whatever time you’d prefer.

Some Variations

Press ENTER khổng lồ continue


Here -d $"e" determines that the Escape key (\e) is the “final” character (kind-a like using the ENTER key). So be aware that the user can type a bunch of other characters (not displayed) before they press Escape.

Note : the “Press any key to lớn continue” would have worked with the Escape key as well … & may even be the better solution unless pressing Escape is required.


Twitter - Share this page ..."> Facebook - Share this page ..."> Pinterest - Share this page ..."> Digg - Share this page ..."> Reddit - Share this page ..."> StumbleUpon - Share this page ..." style="margin-right:10px;"> eMail - eMail this page to friends ..."> Print - Print this page ..." style="margin-right:10px;"> Share this page at ... - Additional Services!" style="margin-right:4px;"> Sharing this page - This page has been shared this many times">

Your tư vấn is very much appreciated, and can be as easy as sharing a link lớn my trang web with others, or on social truyền thông.Support can also be done by sponsoring me, and even that can be free (e.g. cửa hàng at Amazon).Any funds received from your support will be used for web-hosting expenses, project hardware & software, coffee, etc.Thank you very much for those that have shown tư vấn already!It"s truly amazing khổng lồ see that folks lượt thích my articles & small applications.Please note that clicking affiliate links, lượt thích the ones from Amazon, may result in a small commission for us - which we highly appreciate as well.


Ad Blocking Detected

Please consider disabling your ad blocker for our trang web.We rely on these ads to be able to run our website.You can of course tư vấn us in other ways (see Support Us on the left).


Ad Blocking Detected

Please consider disabling your ad blocker for our website.We rely on these ads lớn be able to run our trang web.You can of course support us in other ways (see Support Us on the left).


There are 4 comments. You can read them below.You can post your own comments by using the size below, or reply to existing comments by using the "Reply" button.


Do not post large files here (lượt thích source codes, log files or config files). Please use the Forum for that purpose.
Please share: Twitter - Share this page ..."> Facebook - Share this page ..."> Pinterest - Share this page ..."> Digg - Share this page ..."> Reddit - Share this page ..."> StumbleUpon - Share this page ..." style="margin-right:10px;">
Your name Your name - Required!" pattern=".3," required>*
Your eMail address Your eMail address - Required!" required pattern="^()+
()+.(2,4)$">*
Your trang web (optional) Your website - Optional." pattern="((http?://)?(w+)(-w+)?(.w+)+(:d+)?(/*.?*)*(?*(=*)?(&*(=*)?)*)?(#*)?)">
Your Comment Your Comment - Required!">
Notify me about new comments (email). You can also use your RSS reader khổng lồ traông xã comments.
Submit Reply Cancel Reply Cancel Reply
Gravatar Caching - Gravatar icons will be cached for 2 weeks khổng lồ improve loading tốc độ."> crewcutandnewt.com uses the không lấy phí Gravatar service for Avatar display. crewcutandnewt.com will never giới thiệu your email address with others.

Support Us

Your support is highly appreciated ... Please note that clicking on Amazon links may result in a small commission for us.

Link QR Code

*

Quiông xã Navigation

Common Pages

Language

Article Navigation

3 chiều PrintingApplicationsCD, DVD, Blu-Ray Disc BurningBurning for LinuxBurning for MacOS XBurning for WindowsGeneric ArticlesGraphics & DesignIllustratorPhotoshopHardwareApple ComputersArduinoArduino Programming for BeginnersCables và ConnectorsESP8266PC"sRaspberry PiXBoxHome TheatreAppleTVKodi (XBMC)điện thoại DevicesAndroidRepurpose your old AndroidApple iOSRepurpose old iOS devicesGPSWindows TabletsMusicLinux & MusicMacOS X và MusicWindows and MusicNetwork và InternetOnline ToolsOS Tips & TricksMacOS X TricksPhotographyQNAPSoftwareGamesLinuxMacOS XWindowsSoftware DevelopmentDelphiLazarus FPCVideoGamingđiện thoại VideoRip DVD or Blu-RayWeb DevelopmentGeneric Web DesignWordPress

Most Recent Articles

2021

2020

Recent Comments

2021

Recent Forum Topics

2021

Interesting Links

New Downloads

Amazon Ads

Support us by doing your shopping at Amazon.com, either cliông xã the liên kết, or cliông chồng one of the link below …

You can also sponsor us through these Amazon offerings:


Ad Blocking Detected

Please consider disabling your ad blocker for our trang web.We rely on these ads lớn be able to lớn run our website.You can of course tư vấn us in other ways (see Support Us on the left).


©2000-2021 Hans Luijten - crewcutandnewt.com / WeetHet.nl.

Xem thêm: Auto Trả Lời Tin Nhắn Facebook, Trả Lời Tin Nhắn Tự Động Messenger

Content may not be reproduced without explicit permission of the author(s).You can liên hệ us through the "Contact Us" form.Linking to lớn our page(s) however is very much appreciated.


crewcutandnewt.com uses cookies khổng lồ ensure the best experience on our trang web. If you continue to use this site we will assume that you are OK with that.OKDetails

Chuyên mục: Công nghệ