LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
Go Back   LinuxQuestions.org > Blogs
User Name
Password

Notices


Old

Pure Bash option handling

Posted 04-16-2012 at 01:44 AM by Nominal Animal

I like the standard getopt way of specifying script and/or program parameters, but I don't like its quirks, and it is pretty cryptic if you don't use it often enough.

Here is pure Bash skeleton to implement script option parsing. It is long, but it should be easier to read and understand than one implemented using getopt.
Code:
#!/bin/bash
set +f                  # Enable filename globbing
set -B                  # Enable brace expansion
shopt -s dotglob
...
Senior Member
Posted in Uncategorized
Views 2513 Comments 0 Nominal Animal is offline
Old

Handling all file names safely in Bash

Posted 02-11-2012 at 12:09 PM by Nominal Animal
Updated 04-16-2012 at 02:41 AM by Nominal Animal (Fuller fixes.)
Tags bash, filename, nul

In Linux, each file or directory name (or more generally, pathname component) is just a string of bytes. It always ends with the C end-of-string mark, ASCII NUL: a zero. Value 47, ASCII /, is also reserved for use as a separator between pathnames.

Bash can read ASCII NUL separated data using read -d "" variable. It will, however, remove leading and trailing characters that match IFS, and return false (nonzero status) if the input does not have a final NUL. This applies to...
Senior Member
Posted in Uncategorized
Views 2247 Comments 0 Nominal Animal is offline
Old
Rating: 4 votes, 4.00 average.

Bash scripts and keyboard input

Posted 01-29-2012 at 02:43 PM by Nominal Animal

You can use Bash to read individual keypresses. Here is an example:
Code:
#!/bin/bash

# Reset terminal to current state when we exit.
trap "stty $(stty -g)" EXIT

# Disable echo and special characters, set input timeout to 0.2 seconds.
stty -echo -icanon time 2 || exit $?

# String containing all keypresses.
KEYS=""

# Set field separator to BEL (should not occur in keypresses)
IFS=$'\a'
...
Senior Member
Posted in Uncategorized
Views 12858 Comments 0 Nominal Animal is offline

  



All times are GMT -5. The time now is 11:03 PM.

Main Menu
Advertisement
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration