Sponsored Content
Top Forums Shell Programming and Scripting Tip: template for a safe and portable script Post 303032522 by MadeInGermany on Tuesday 19th of March 2019 02:47:02 PM
Old 03-19-2019
Tip: template for a safe and portable script

In an attempt to finally end this article I start this new thread.
Here is a template for a safe and portable script.
Code:
#!/bin/bash
# /bin/bash exists on most still supported Unixes
#
# tr and date behave better with
if [ -n "$LC_ALL" ]; then export LC_ALL=C; else export LANG=C; fi
#
# Unix optional packages install in
opt_path=/usr/local/bin
solaris_opt_path=/usr/sfw/bin:/opt/csw/bin
#
# set PATH so no PATH is inherited, export it to all children
# Solaris is Posix-compliant in /usr/xpg4/bin and BSD-compliant in /usr/ucb
export PATH=/usr/xpg4/bin:/bin:/usr/bin:/sbin:/usr/sbin:/usr/ucb:${opt_path}:${solaris_opt_path}
#
# HP-UX is Posix-compliant with
export UNIX95=
#
# GREP_OPTIONS can obscure GNU grep
unset GREP_OPTIONS
#
# LD_* can obscure external commands
unset LD_LIBRARY_PATH LD_PRELOAD
#
# no glob file-matching in command args and word lists (for loop)
set -f
#
# prefer builtin commands and use Posix-compliant options
# check with "shellcheck"

Ok this is my wisdom. Perhaps you want to add something from your wisdom?
 
script(1)							   User Commands							 script(1)

NAME
script - make record of a terminal session SYNOPSIS
script [-a] [filename] DESCRIPTION
The script utility makes a record of everything printed on your screen. The record is written to filename. If no file name is given, the record is saved in the file typescript. See WARNINGS. The script command forks and creates a sub-shell, according to the value of $SHELL, and records the text from this session. The script ends when the forked shell exits or when Control-d is typed. OPTIONS
The following option is supported: -a Appends the session record to filename, rather than overwriting it. NOTES
script places everything that appears on the screen in filename, including prompts. ATTRIBUTES
See attributes(5) for descriptions of the following attributes: +-----------------------------+-----------------------------+ | ATTRIBUTE TYPE | ATTRIBUTE VALUE | +-----------------------------+-----------------------------+ |Availability |SUNWcsu | +-----------------------------+-----------------------------+ |CSI |Enabled | +-----------------------------+-----------------------------+ SEE ALSO
attributes(5) WARNINGS
script can pose a security risk when used in directories that are writable by other users (for example, /tmp), especially when run by a privileged user, that is, root. Be sure that typescript is not a link before running script. SunOS 5.11 30 Jan 2004 script(1)
All times are GMT -4. The time now is 01:25 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy