Use parameter expansion over a parameter expansion in bash.
Hello All,
Could you please do help me here as I would like to perform parameter expansion in shell over a parameter expansion.
Let's say I have following variable.
Now to get only nat I could do following.
Here in this approach I am creating a temporary variable path1 and again performing parameter expansion, how about if I want to perform this in single time without having temporary variable? I have tried it like:
Which is giving me an error. Any help, guidance is appreciated.
Thanks,
R. Singh
This User Gave Thanks to RavinderSingh13 For This Post:
Hi all-
I have a variable that contains a web page:
echo $STUFF
<html> <head> <title>my page</title></head> <body> blah blah etc..
Can I use the shell's parameter expansion abilities to remove just the tags?
I thought that FIXHTML=${STUFF//<*>/} might do it, but it didn't seem to... (2 Replies)
Hi ,
could anyone help me out with this problem.
sample.txt has this content :
u001- this is used for project1 ||
u002- this is used for p2|| not to be printed
u003- this is used
for project3 ||
u004- this is
used for p4 ||
u005- this is used for project5 ||
u006- this is used for p6... (9 Replies)
Say you have this numeric variable that can be set by the user but you never want it to leave a certain range when it gets printed. How could you use parameter expansion such that it will never expand outside of that boundary? Thanks
---------- Post updated at 11:09 PM ---------- Previous update... (3 Replies)
Hi -
I am trying to do a simple config file with known variable names in it, e.g.:
contents of config file a.conf: -a
-b $work
-c $host
simplified contents of bash script file: work='trunk'
host='alaska'
opts=$(tr '\n' ' ' < a.conf)
opts="$opts $*"
mycommand $opts arg1 arg2
The... (3 Replies)
I'm trying to write a script that parses my music collection and hard link some filenames that my media player doesn't like to other names.
To do this I need to extract the name and remove alla non ASCII characters from that and do a cp -l with the result.
Problem is this:
22:16:58 $... (8 Replies)
Hello experts,
I am exploring parameter expansion, and trying to cut the fields in a URL.
Following is the requirement:
I have
// abc.nnt /dir1/dir2/dir3/dir4/somefile.java
What i need to get is the path after dir3, and dir3 will be passed.
output that i need is... (1 Reply)
I have made the following examples that print various parameter expansions
text: iv-hhz-sac/hpac/hhz.d/iv.hpac..hhz.d.2016.250.070018.sac
(text%.*): iv-hhz-sac/hpac/hhz.d/iv.hpac..hhz.d.2016.250.070018
(text%%.*): iv-hhz-sac/hpac/hhz
(text#*.): d/iv.hpac..hhz.d.2016.250.070018.sac... (2 Replies)
#!/bin/bash
SNMPW='/usr/bin/snmpwalk'
while read h i
do
loc=$($SNMPW -v3 -u 'Myusername' -l authPriv -a SHA -A 'Password1' -x AES -X 'Password2' $i sysLocation.0 2>/dev/null)
loc=${loc:-" is not snmpable."}
loc=${loc##*: }
loc=${loc//,/}
echo "$i,$h,$loc"
done < $1
My question is ... ... (1 Reply)
I am trying to become more fluent with the interworking of bash and minimize the number of external calls.
Sample Data. This will be the response of the snmp query.
SNMPv2-MIB::sysName.0 = STRING: SomeHostName
SNMPv2-MIB::sysObjectID.0 = OID: SNMPv2-SMI::enterprises.9.1.1745... (5 Replies)
Example data
$ ls *somehost*
10.10.10.10_somehost1.xyz.com.log
11.11.11.11_somehost2.xyz.com.log
#!/bin/bash
#FILES="*.log"
FILES=${FILES:-*.log}
for x in $FILES
do
ip="${x%%_*}" # isolate IP address
x="${x##*_}" # isolate hostname
hnam="${x%.*}" # Remove the ".log"... (2 Replies)
Discussion started by: popeye
2 Replies
LEARN ABOUT OSX
link
LINK(2) BSD System Calls Manual LINK(2)NAME
link -- make a hard file link
SYNOPSIS
#include <unistd.h>
int
link(const char *path1, const char *path2);
DESCRIPTION
The link() function call atomically creates the specified directory entry (hard link) path2 with the attributes of the underlying object
pointed at by path1. If the link is successful, the link count of the underlying object is incremented; path1 and path2 share equal access
and rights to the underlying object.
If path1 is removed, the file path2 is not deleted and the link count of the underlying object is decremented.
In order for the system call to succeed, path1 must exist and both path1 and path2 must be in the same file system. As mandated by POSIX.1,
path1 may not be a directory.
link() will resolve and follow symbolic links contained within both path1 and path2. If the last component of path1 is a symbolic link,
link() will point the hard link, path2, to the underlying object pointed to by path1, not to the symbolic link itself.
RETURN VALUES
Upon successful completion, a value of 0 is returned. Otherwise, a value of -1 is returned and errno is set to indicate the error.
ERRORS
Link() will fail and no link will be created if:
[EACCES] A component of either path prefix denies search permission.
[EACCES] The requested link requires writing in a directory with a mode that denies write permission.
[EACCES] The current process cannot access the existing file.
[EDQUOT] The directory in which the entry for the new link is being placed cannot be extended because the user's quota of disk
blocks on the file system containing the directory has been exhausted.
[EEXIST] The link named by path2 already exists.
[EFAULT] One of the pathnames specified is outside the process's allocated address space.
[EIO] An I/O error occurs while reading from or writing to the file system to make the directory entry.
[ELOOP] Too many symbolic links are encountered in translating one of the pathnames. This is taken to be indicative of a looping
symbolic link.
[EMLINK] The file already has {LINK_MAX} links.
[ENAMETOOLONG] A component of a pathname exceeds {NAME_MAX} characters, or an entire path name exceeded {PATH_MAX} characters.
[ENOENT] A component of either path prefix does not exist, or is a dangling symbolic link.
[ENOENT] The file named by path1 does not exist, or is a dangling symbolic link.
[ENOSPC] The directory in which the entry for the new link is being placed cannot be extended because there is no space left on the
file system containing the directory.
[ENOTDIR] A component of either path prefix is not a directory.
[EPERM] The file named by path1 is a directory.
[EROFS] The requested link requires writing in a directory on a read-only file system.
[EXDEV] The link named by path2 and the file named by path1 are on different file systems.
SEE ALSO symlink(2), unlink(2)STANDARDS
The link() function is expected to conform to IEEE Std 1003.1-1988 (``POSIX.1'').
4th Berkeley Distribution October 29, 2008 4th Berkeley Distribution