Sponsored Content
Top Forums Shell Programming and Scripting Real-time scenarios where VARIABLE SUBSTITUTION/EXPANSION is useful Post 302946369 by cfajohnson on Monday 8th of June 2015 06:29:06 PM
Old 06-08-2015
Probably my most frequent use is to get the filename from a full path, essentally replacing the basename command:

Code:
path=/path/to/file
file=${path##*/}

 

5 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

sed insert command and variable expansion/command substitution

I know this script is crummy, but I was just messing around.. how do I get sed's insert command to allow variable expansion to show the filename? #!/bin/bash filename=`echo $0` /usr/bin/sed '/#include/ { i\ the filename is `$filename` }' $1 exit 0 (8 Replies)
Discussion started by: glev2005
8 Replies

2. Shell Programming and Scripting

[Solved] Command Substitution and Variable Expansion within a Case

Hello All, I don't write scripts very often, and in this case I am stumped, although it may be a bug in the version of bash I have to use (it's not my system). I want to extract a specific string snippet from a block of text (coming from a log file) that is dependent on a bunch of other... (1 Reply)
Discussion started by: jaimielives
1 Replies

3. Shell Programming and Scripting

Shell script to convert epoch time to real time

Dear experts, I have an epoch time input file such as : - 1302451209564 1302483698948 1302485231072 1302490805383 1302519244700 1302492787481 1302505299145 1302506557022 1302532112140 1302501033105 1302511536485 1302512669550 I need the epoch time above to be converted into real... (4 Replies)
Discussion started by: aismann
4 Replies

4. Shell Programming and Scripting

Converting real time to epoch time

# date +%s -d "Mon Feb 11 02:26:04" 1360567564 # perl -e 'print scalar localtime(1360567564), "\n";' Mon Feb 11 02:26:04 2013 the epoch conversion is working fine. but one of my application needs 13 digit epoch time as input 1359453135154 rather than 10 digit epoch time 1360567564... (3 Replies)
Discussion started by: vivek d r
3 Replies

5. Shell Programming and Scripting

sed variable expansion fails for substitution in range

I'm trying to change "F" to "G" in lines after the first one: 'FUE.SER' 5 1 1 F0501 F0401 F0502 2 1 F0301 E0501 F0201 E0502 F0302 3 1 F0503 E0503 E0301 E0201 E0302 E0504 F0504 4 1 F0402 F0202 E0202 F0101 E0203 F0203 F0403 5 1 F0505 E0505 E0303 E0204 E0304 E0506... (10 Replies)
Discussion started by: larrl
10 Replies
basename(3C)															      basename(3C)

NAME
basename(), dirname() - extract components of a path name SYNOPSIS
DESCRIPTION
takes the path name pointed to by path and returns a pointer to the final component of the path name, deleting any trailing '/' characters. If the string consists entirely of '/' characters, returns a pointer to the string "/". If path is a null pointer or points to the empty string, returns a pointer to the string ".". takes the path name pointed to by path and returns a pointer to a string that is a path name of the parent directory of that file. If path is a null pointer, points to the empty string, or does not contain a '/' character, then returns a pointer to the string ".". RETURN VALUE
returns a pointer to the final component of path. returns a pointer to a string that is the parent directory of path. EXAMPLES
The following code fragment calls and WARNINGS
and may overwrite path. and in non-threaded applications currently use a static buffer in each function to hold the result string. Any subsequent calls to and may overwrite the static buffer. At some release after HP-UX 11i Version 1, HP may use to allocate the buffers. Once allocated, those buffers will be reused and their addresses will not change; however, if the fails, and would return "." and would be set to AUTHOR
and were developed by HP. SEE ALSO
basename(1), thread_safety(5). STANDARDS CONFORMANCE
basename(3C)
All times are GMT -4. The time now is 01:13 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy