/
usr
/
local
/
stat_watch
/
includes
/
File Upload :
llllll
Current File: //usr/local/stat_watch/includes/util.shf
#! /bin/bash function fn_file_path { ### Given a file (whether or not with full path), populate the variables "$s_FILE" and "$s_DIR" with the file and the directory ### The problem with realpath and readlink is that if the file is a symlink, then it will give us the path to the file that it links to. We don't want that. ### This gives us the real path to the directory, but keeps the filename local v_FILE="$1" ### If the file name ends in a slash, remove that slash if [[ "${v_FILE: -1}" == "/" ]]; then v_FILE="${v_FILE:0:${#v_FILE}-1}" fi ### Separate out the file name from the path s_FILE="${v_FILE##*/}" ### Find the length of the path local v_DIR_LEN=$(( ${#v_FILE} - ${#s_FILE} - 1 )) if [[ "$v_DIR_LEN" -le 0 ]]; then if [[ "${v_FILE:0:1}" == "/" ]]; then ### if we were given a full path and the dir length is zero, the parent must be "/" s_DIR="/" else ### If no path was given, let's find it s_DIR="$( pwd )" fi else ### If a path was given, we'll find out what it really is s_DIR="${v_FILE:0:$v_DIR_LEN}" fi ### find the real path local s_DIR2="$( readlink "$s_DIR" 2> /dev/null )" if [[ -n "$s_DIR2" ]]; then s_DIR="$s_DIR2" fi } function fn_sanitize { ### Given a variable that we're goingg to run through an egrep, escape all special characters local v_OUTPUT="${1//\\/\\\\}" v_OUTPUT="${v_OUTPUT//\*/\\*}" v_OUTPUT="${v_OUTPUT//\./\\.}" v_OUTPUT="${v_OUTPUT//[/\\[}" v_OUTPUT="${v_OUTPUT//|/\\|}" v_OUTPUT="${v_OUTPUT//\?/\\?}" v_OUTPUT="${v_OUTPUT//\(/\\(}" v_OUTPUT="${v_OUTPUT//)/\\)}" v_OUTPUT="${v_OUTPUT//$/\\$}" v_OUTPUT="${v_OUTPUT//+/\\+}" v_OUTPUT="${v_OUTPUT//^/\\^}" v_OUTPUT="${v_OUTPUT//{/\\{}" echo -n "$v_OUTPUT" }
Copyright ©2k19 -
Hexid
|
Tex7ure