Sponsored Content
Top Forums UNIX for Dummies Questions & Answers Environment Variable with Special characters Post 302644189 by neutronscott on Monday 21st of May 2012 11:58:57 AM
Old 05-21-2012
What shell are you using? I'm only famaliar with bash, but I think you're using ksh. Seems the expansions are done in different order.

bash:
Code:
[mute@geek ~/temp/sethmj]$ shopt -s extglob
[mute@geek ~/temp/sethmj]$ FILE_ARG=FILE_NM_?(20120515|20120516)??????_sas.sig
[mute@geek ~/temp/sethmj]$ echo "$FILE_ARG"
FILE_NM_?(20120515|20120516)??????_sas.sig
[mute@geek ~/temp/sethmj]$ ls -lt $FILE_ARG
-rw-r--r-- 1 mute mute 0 May 21 15:46 FILE_NM_20120515000000_sas.sig
-rw-r--r-- 1 mute mute 0 May 21 15:44 FILE_NM_20120516000000_sas.sig

ksh:
Code:
$ FILE_ARG=FILE_NM_?(20120515|20120516)??????_sas.sig
$ echo "$FILE_ARG"
FILE_NM_?(20120515|20120516)??????_sas.sig
$ ls -lt $FILE_ARG
ls: cannot access FILE_NM_?(20120515|20120516)??????_sas.sig: No such file or directory
$ ls -lt FILE_NM_?(20120515|20120516)??????_sas.sig
-rw-r--r-- 1 mute mute 0 May 21 15:46 FILE_NM_20120515000000_sas.sig
-rw-r--r-- 1 mute mute 0 May 21 15:44 FILE_NM_20120516000000_sas.sig

Neither does filename expansion on variable assignment. Except with arrays:

Code:
$ files=( FILE_NM_?(20120515|20120516)??????_sas.sig ); echo "${files[@]}"
FILE_NM_20120515000000_sas.sig FILE_NM_20120516000000_sas.sig

edit: If you're looking for the latest file matching the glob, try:

Code:
unset latest
for file in FILE_NM_?(20120515|20120516)??????_sas.sig
do
  [[ $file -nt $latest ]] && latest=$file
done
 
echo "$latest"


Last edited by neutronscott; 05-21-2012 at 01:07 PM..
This User Gave Thanks to neutronscott For This Post:
 

10 More Discussions You Might Find Interesting

1. UNIX for Advanced & Expert Users

Special characters getting replaced by &Pound in Unix Environment

Hi, Please find the Question Summary below- In our email template document(.txt) bullets and Apostrophe are getting replaced by the string "&pound" in our Live environment.We are using sun solaris 8 in live. Can anybody let me know why this happens and how to prevent this . Thanks... (0 Replies)
Discussion started by: kaushik05
0 Replies

2. Shell Programming and Scripting

Variable Manimpulation - special characters

Hello- I have a variables that contains a string like this usr/pass@SCHEMA I want to extract the usr/pass part and ignore the SCHEMA part, I tried to use this ${dbconn%%@} and apparently it will not work because @ is a special character. I tried \@ and still no go. Any idea how to solve... (1 Reply)
Discussion started by: Nomaad
1 Replies

3. Shell Programming and Scripting

Special characters in a bash variable in sed

Hello, I am trying the following: echo __CHANGEME__ >> testfile VAR1="&&&" sed -i "s|__CHANGEME__|${VAR1}|" testfile cat testfile This results in testfile containing __CHANGEME____CHANGEME____CHANGEME__ Whereas I want it to result in &&& I understand that if VAR1="\&\&\&" then... (3 Replies)
Discussion started by: linuxnewbeee
3 Replies

4. UNIX for Dummies Questions & Answers

How to see special characters?

Hi all, I was wondering how can i see the special characters like \t, \n or anything else in a file by using Nano or any other linux command like less, more etc (6 Replies)
Discussion started by: gvj
6 Replies

5. Shell Programming and Scripting

Sed failing for variable with special characters

This has been covered many times earlier but couldnt figure the issue myself. Can you please advise whats wrong on the below code I have a variable with special character ($) and am using that variable to replace another variable in file but however sed is failing to parse it correctly ... (7 Replies)
Discussion started by: sasiharitha
7 Replies

6. Shell Programming and Scripting

special characters

Hey guys, I'm trying to replace "]Facebook" from the text but sed 's/]Facebook/Johan/g' is not working could you please help me with that? (6 Replies)
Discussion started by: Johanni
6 Replies

7. Shell Programming and Scripting

Replace special characters with Escape characters?

i need to replace the any special characters with escape characters like below. test!=123-> test\!\=123 !@#$%^&*()-= to be replaced by \!\@\#\$\%\^\&\*\(\)\-\= (8 Replies)
Discussion started by: laknar
8 Replies

8. Shell Programming and Scripting

Trouble with sed and substituting a string with special characters in variable

Hey guys, I know that title is a mouthful - I'll try to better explain my struggles a little better... What I'm trying to do is: 1. Query a db and output to a file, a list of column data. 2. Then, for each line in this file, repeat these values but wrap them with: ITEM{ ... (3 Replies)
Discussion started by: ampsys
3 Replies

9. Shell Programming and Scripting

Parsing special characters from variable commands

Hi, I am fairly new to unix scripting and recently tasked with some reporting scripts. The reporting checks several batch jobs and this is quite iterative. Now I am trying to minimize script effort and maximize reusability as there are only slight nuances in the repetitive tasks. For... (3 Replies)
Discussion started by: joeniks
3 Replies

10. Shell Programming and Scripting

awk match shell variable that contains special characters?

How to match a shell variable that contains parenthesis (and other special characters like "!") file.txt contains: Charles Dickens Matthew Lewis (writer) name="Matthew Lewis (writer)"; awk -v na="$name" ' $0 ~ na' file.txt Ideally this would match $name in file.txt (in this... (3 Replies)
Discussion started by: Mid Ocean
3 Replies
ssignal(3C)						   Standard C Library Functions 					       ssignal(3C)

NAME
ssignal, gsignal - software signals SYNOPSIS
#include <signal.h> void(*ssignal (int sig, int (*action)(int)))(int); int gsignal(int sig); DESCRIPTION
The ssignal() and gsignal() functions implement a software facility similar to signal(3C). This facility is made available to users for their own purposes. ssignal() Software signals made available to users are associated with integers in the inclusive range 1 through 17. A call to ssignal() associates a procedure, action, with the software signal sig; the software signal, sig, is raised by a call to gsignal(). Raising a software signal causes the action established for that signal to be taken. The first argument to ssignal() is a number identifying the type of signal for which an action is to be established. The second argument defines the action; it is either the name of a (user-defined) action function or one of the manifest constants SIG_DFL (default) or SIG_IGN (ignore). The ssignal() function returns the action previously established for that signal type; if no action has been established or the signal number is illegal, ssignal() returns SIG_DFL. gsignal() The gsignal() raises the signal identified by its argument, sig. If an action function has been established for sig, then that action is reset to SIG_DFL and the action function is entered with argument sig. The gsignal() function returns the value returned to it by the action function. If the action for sig is SIG_IGN, gsignal() returns the value 1 and takes no other action. If the action for sig is SIG_DFL, gsignal() returns the value 0 and takes no other action. If sig has an illegal value or no action was ever specified for sig, gsignal() returns the value 0 and takes no other action. ATTRIBUTES
See attributes(5) for descriptions of the following attributes: +-----------------------------+-----------------------------+ | ATTRIBUTE TYPE | ATTRIBUTE VALUE | +-----------------------------+-----------------------------+ |MT-Level |Unsafe | +-----------------------------+-----------------------------+ SEE ALSO
raise(3C), signal(3C), attributes(5) SunOS 5.11 29 Dec 1996 ssignal(3C)
All times are GMT -4. The time now is 06:23 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy