Skip to content

Instantly share code, notes, and snippets.

@masato9000
Last active April 7, 2021 20:23
Show Gist options
  • Save masato9000/b7d9d160c96506e8cea78d5f2b88edf2 to your computer and use it in GitHub Desktop.
Save masato9000/b7d9d160c96506e8cea78d5f2b88edf2 to your computer and use it in GitHub Desktop.
Shell script that prompts for input and immediately discards it
#!/bin/sh
bsdl='
Copyright (c) 2018, masato9000@users.noreply.github.com
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
1. Redistributions of source code must retain the above copyright notice, this
list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
'
thank_you() {
# be gracious
printf %b "\033c"
echo Don\'t worry.
echo This is between you and nobody.
exit
}
trap thank_you INT
printf %b "\033c"
while [ whatever ]; do
echo Please, say whatever you want. Nobody will know.
echo Just send SIGINT when you\'ve gotten it all out.
read _secret
_secret=""
printf %b "\033c"
done
@masato9000
Copy link
Author

Just a quick and dirty aid for when there's just no other outlet...

@masato9000
Copy link
Author

masato9000 commented Apr 7, 2021

change some echos to printf %b because of INCORRECT posix mode echo implementation on some BASH4 builds, MKSH, and Mac KSH (but suprisingly, NOT bash3 on Mac)
ugh...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment