Removing a character from a variable and assigning it to another variable?


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Removing a character from a variable and assigning it to another variable?
# 8  
Old 02-22-2010
Tools With the tr command

Code:
FirstIN=001,002,003,004
ModIN=$(echo "$FirstIN" | tr "," " ")

or
Code:
ModIN=`echo "$FirstIN" | tr "," " "`

# 9  
Old 02-22-2010
Quote:
Originally Posted by Corona688
It's not a bash-ism. It works fine in a bourne shell. I even tested it in busybox ash, one of the most limited, stripped-down, barebones bourne shells still available today.
...But if I recall correctly it is still a POSIX shell. Older ksh and true bourne shell (solaris) probably won't know what to do with it.
# 10  
Old 02-22-2010
That would explain why it even works in vanilla ksh when I finally caved in and installed it. Solaris still ships with non-POSIX shells? How lovely to get accused of BASH-ism for following POSIX...

Where can I find such a truly garbage shell to test with, to ensure code we suggest will work with solaris? Smilie
# 11  
Old 02-22-2010
On Solaris Smilie

Even the sun guys find it odd but in Solaris backward compatibility is king, so taking anything out once it's there is hard. There are POSIX shells on Solaris also but probably the most common environment that I see for a POSIX shell snippet not working in a given environment is Solaris.
# 12  
Old 02-22-2010
Quote:
Originally Posted by Corona688
It's not a bash-ism.
You are quite correct.

KSH93 supports it (perhaps it originated there?), but KSH88 does not. I suspect that SFNYC, like myself, is using pdksh which is KSH88 for the most part.

For the sticklers, it still hasn't found its way into the POSIX sh standard.

Thanks for the correction, Corona688.

Regards,
Alister
# 13  
Old 02-22-2010
Interesting. It wasn't working for me on Linux using

Code:
$ echo $SHELL
/bin/ksh

$ echo $KSH_VERSION
@(#)PD KSH v5.2.14 99/07/13.2

So, is this version of KSH not POSIX-compliant?
# 14  
Old 02-22-2010
Quote:
Originally Posted by SFNYC
Interesting. It wasn't working for me on Linux using

Code:
$ echo $SHELL
/bin/ksh

$ echo $KSH_VERSION
@(#)PD KSH v5.2.14 99/07/13.2

So, is this version of KSH not POSIX-compliant?

pdksh is mostly ksh88 and that feature was not introduced in ksh until ksh93.

POSIX compatibility is irrelevant as this type of parameter expansion is NOT in the POSIX standard.

See Section 2.6.2 of Shell Command Language

Regards,
Alister
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

awk - Removing extra character when setting variable

I have a data file d0 that looks like this: $cat d0 server1 running -n-cv- 8G 3.1% 1435d 15h server2 running -n---- 8G 39% 660d 22h server3 running -n--v- 8G 2.5% 1173d 6h server4 running -n---- 8G 1.1% 1048d 20h... (2 Replies)
Discussion started by: jake0391S
2 Replies

2. Shell Programming and Scripting

Assigning a variable

I have a date column as 06302015 but I need to have variable which extracts 063015. Am trying something like below but it is not assigning Please let me know if am missing something. Thanks in advance. ################################ #!/usr/bin/ksh DT=06302015 ... (7 Replies)
Discussion started by: weknowd
7 Replies

3. Shell Programming and Scripting

Assigning value to a variable

Unable to get the value to a variable. set -x cd $HOME echo "Enter the server name" read a echo $a i=4 j=1 k = ps -ef | awk '/server1/{ print $4 }' | tail -$i | head -$j` echo $k When I do the same in command line it works, however the same does not work when I provide that in the... (1 Reply)
Discussion started by: venkidhadha
1 Replies

4. Shell Programming and Scripting

Assigning a value to a variable

Hi I have a script that accepts an input date in YYYY-MM-DD format. After that, I used sed to delete the hyphen (-) which gives me an output YYYY MM DD. My question is, how can I assign those three numbers to a three different variable. Example: 2013-11-23 will become 2013 11 23... (4 Replies)
Discussion started by: erin00
4 Replies

5. Shell Programming and Scripting

problem in assigning value to variable have value fo other variable

my script is some thing like this i11="{1,2,3,4,5,6,7,8,9,10,11,}" echo "enter value" read value ..............suppose i11 x="$value" echo "$($value)" .............the echo should be {1,2,3,4,5,6,7,8,9,10,11,} but its showing "i11" only. plz help me out to get desired... (10 Replies)
Discussion started by: sagar_1986
10 Replies

6. UNIX for Advanced & Expert Users

couting occurences of a character inside a string and assigning it to a variable

echo "hello123" | tr -dc '' | wc -c using this command i can count the no of times a number from 0-9 occurs in the string "hello123" but how do i save this result inside a variable? if i do x= echo "hello123" | tr -dc '' | wc -c that does not work...plz suggest..thanks (3 Replies)
Discussion started by: arindamlive
3 Replies

7. Shell Programming and Scripting

assigning a variable

hi all, in ksh, how do i assign the output of a find command to a variable, e.g am trying something like this : totalNoFiles=$(print find ./ -name "SystemOut*.log"); but when i echo $totalNoFiles it displays find ./ -name "SystemOut*.log" instead of the total number of... (2 Replies)
Discussion started by: cesarNZ
2 Replies

8. Shell Programming and Scripting

Removing character ' from a variable

Hello there, I have a variable in the form of '/example/file.txt' . I want to remove the ' characters from the beginning and the end so that the my new variable becomes /example/file.txt . How can I do it in a script? I know this is a fairly easy question, but i wasn't able to implement it. (3 Replies)
Discussion started by: sertansenturk
3 Replies

9. Shell Programming and Scripting

Assigning Value of variable

Hi In my shell script, I'm trying to find the line count of a file and assign it to a variable. LINE_COUNT=$(wc -l $FILE_NAME) But when i display LINE_COUNT, i'm getting the linecount concatenated with the file name. I want only the number. How can i get the line count alone ? Someone... (2 Replies)
Discussion started by: janemary.a
2 Replies

10. Shell Programming and Scripting

Assigning a value to variable

Another newbie to Unix scripting Q.. How do you assign a value resulting from a command, such as awk, to a variable. I am currently trying:- $awk '{print $1}' file1 > variable1 with no change to $variable1. The line: $awk '{print $1}' file1 does print the first line of the... (3 Replies)
Discussion started by: sirtrancealot
3 Replies
Login or Register to Ask a Question