Replacements for standard commands
Functions that should be used instead of standard Unix commands.
Functions in this category
Name | Parameters |
locateCommand |
[OPTIONS] COMMAND [PARAMETERS] |
mkdirs |
--nolog --session <DIRECTORY> |
safeSed |
<FILENAME> <SCRIPTSTRING> |
Details
locateCommand |
Syntax: locateCommand [OPTIONS] COMMAND [PARAMETERS] |
OPTION -r: | run COMMAND even if no parameters are given |
OPTION -o: | print COMMAND's output to stdout |
COMMAND: | required :: executable file to search for |
PARAMETERS: | optional :: if found execute the command with these parameters |
OPTION --: | no printed text (default) |
OPTION -l: | print COMMAND's absolute filename to stdout |
Returns: | 1 if file not located, or if file located, then executed with parameters and exit code > 0; 0 if file is located, or if file is located, then executed with parameters and exit code = 0 |
|
Finds the location of an object with the combined efforts of 'which' then 'whereis'
If PARAMETERS are given, or if -o or -r is given, then it will run COMMAND with PARAMETERS (if any).
Sets variables:
$lc_array - array of filesystem objects matching the requested file
$lc_location - determined filesystem location of the executable file
$lc_output - output data from the executable file using parameters
$lc_ret - return value of COMMAND if COMMAND is run
|
Example:
locateCommand -o kde-config --prefix
---> $lc_array = "/usr/bin/kde-config"
---> $lc_location = "/usr/bin/kde-config"
---> $lc_output = "/usr"
---> $lc_ret = 0
---> returns 0 [ PASS ] and prints '/usr'
found with 'which' so use the 'which' output as $lc_location and
execute command with parameters for $lc_output - check passes and prints result
locateCommand panel
---> $lc_array = "panel: /usr/include/panel.h /usr/share/man/man3/panel.3x.bz2"
---> $lc_location = NULL
---> $lc_output = NULL
---> $lc_ret = NULL
---> returns 1 [ FAIL ]
found with 'whereis' so loop the array for the first executable file and
in this case all objects fail
Same result - different code
if locateCommand gnome-config --datadir; then
gnome1dir="$lc_output/gnome/apps"
fi
gnome1dir=`locateCommand -o gnome-config --datadir`"/gnome/apps"
|
mkdirs |
Syntax: mkdirs --nolog --session <DIRECTORY> |
DIRECTORY: | directory to create. |
--session: | log into session file. |
--nolog: | do not log the function call. |
Returns: | 0, if directory exists or is created; >0, if not created with return code from mkdir. |
|
Create directories within the filesystem and will return error codes if directories
are not created.
Removal of these directories will occur from within the removeFile function such
that mkdirs function will not be logged. |
Example:
mkdirs /home/mike/some/new/dir
--> creates some/new/dir
|
safeSed |
Syntax: safeSed <FILENAME> <SCRIPTSTRING> |
SCRIPTSTRING: | A string containing the script to execute. |
FILENAME: | The file to edit. |
|
This function is like sed, but works on a file. It uses FD swaps internally
so you can reliably edit a file without hitting asyncronity issues. |
Example:
echo 'One Two Three' > foo.txt
safeSed foo.txt 's/One/Two/g'
|