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 MOJAVE
symlink
SYMLINK(2) BSD System Calls Manual SYMLINK(2)NAME
symlink, symlinkat -- make symbolic link to a file
SYNOPSIS
#include <unistd.h>
int
symlink(const char *path1, const char *path2);
int
symlinkat(const char *name1, int fd, const char *name2);
DESCRIPTION
A symbolic link path2 is created to path1 (path2 is the name of the file created, path1 is the string used in creating the symbolic link).
Either name may be an arbitrary path name; the files need not be on the same file system.
The symlinkat() system call is equivalent to symlink() except in the case where name2 specifies a relative path. In this case the symbolic
link is created relative to the directory associated with the file descriptor fd instead of the current working directory. If symlinkat() is
passed the special value AT_FDCWD in the fd parameter, the current working directory is used and the behavior is identical to a call to
symlink().
RETURN VALUES
Upon successful completion, a zero value is returned. If an error occurs, the error code is stored in errno and a -1 value is returned.
ERRORS
The symbolic link succeeds unless:
[EACCES] Write permission is denied in the directory where the symbolic link is being created.
[EACCES] A component of the path2 path prefix denies search permission.
[EDQUOT] The directory in which the entry for the new symbolic 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.
[EDQUOT] The new symbolic link cannot be created because the user's quota of disk blocks on the file system that will contain the
symbolic link has been exhausted.
[EDQUOT] The user's quota of inodes on the file system on which the symbolic link is being created has been exhausted.
[EEXIST] Path2 already exists.
[EFAULT] Path1 or path2 points outside the process's allocated address space.
[EIO] An I/O error occurs while making the directory entry or allocating the inode.
[EIO] An I/O error occurs while making the directory entry for path2, or allocating the inode for path2, or writing out the link
contents of path2.
[ELOOP] Too many symbolic links are encountered in translating the pathname. This is taken to be indicative of a looping symbolic
link.
[ENAMETOOLONG] A component of a pathname exceeds {NAME_MAX} characters, or an entire path name exceeds {PATH_MAX} characters.
[ENOENT] A component of path2 does not name an existing file or path2 is an empty string.
[ENOSPC] The directory in which the entry for the new symbolic link is being placed cannot be extended because there is no space
left on the file system containing the directory.
[ENOSPC] The new symbolic link cannot be created because there there is no space left on the file system that will contain the sym-
bolic link.
[ENOSPC] There are no free inodes on the file system on which the symbolic link is being created.
[ENOTDIR] A component of the path2 prefix is not a directory.
[EROFS] The file path2 would reside on a read-only file system.
In addition to the errors returned by the symlink(), the symlinkat() may fail if:
[EBADF] The name2 argument does not specify an absolute path and the fd argument is neither AT_FDCWD nor a valid file descriptor
open for searching.
[ENOTDIR] The name2 argument is not an absolute path and fd is neither AT_FDCWD nor a file descriptor associated with a directory.
SEE ALSO ln(1), link(2), unlink(2), symlink(7)STANDARDS
The symlinkat() system call is expected to conform to POSIX.1-2008 .
HISTORY
The symlink() function call appeared in 4.2BSD. The symlinkat() system call appeared in OS X 10.10
4.2 Berkeley Distribution June 4, 1993 4.2 Berkeley Distribution