How to modify the variable


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting How to modify the variable
# 1  
Old 06-11-2008
How to modify the variable

I have a directory name stored in a variable. Does anyone have a piece of code which checks if this stored directory name ends up with the "/" and if it is missing adds it to the same variable. for example I might have
A=/bb/data or A=/bb/data/
which needs to be A=/bb/data/ for sure
thanks a lot to all for help -A
# 2  
Old 06-11-2008
You did not specify what shell you are using. However, the following works for ksh93 - assuming A contains the directory variable.

Code:
[[ ${A:${#A}-1} != '/' ]] && A="${A}/"

# 3  
Old 06-11-2008
Thanks a lot, I am using ksh in my scripting, will this code work?
# 4  
Old 06-12-2008
It depends on which version of ksh you are using. There are 3 major versions of ksh in general use - ksh88, pdksh and ksh93.
# 5  
Old 06-12-2008
Another one:

Code:
case $A in */);;*)A=$A/;;esac

# 6  
Old 06-12-2008
I am using ksh88
@(#)Version M-11/16/88i

The above command fails with the following output
op - sundev1 $ [[ ${A:${#A}-1} != '/' ]] && A="${A}/"
ksh: ${A:${#A}-1}: bad substitution

Not sure how to fix it... Any idea? Thanks a lot in advance -A
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Please modify solution

Hi Please check my code,here awk -vLIT="$line" '$0 ~ LIT { print LIT,"Found in ",FILENAME; }' $f it is not checking for small alphabets.can u pls modify my code #!/bin/ksh for f in /tmp/satemp/* do cat /tmp/sa/tt.txt| while read line do awk -vLIT="$line" '$0 ~ LIT { print LIT,"Found in... (3 Replies)
Discussion started by: coolboy98699
3 Replies

2. UNIX for Dummies Questions & Answers

How to modify an output?

I have a list XPAR XPAR XPAR , XPAR , , XPAR ,1, XPAR 196 XPAR 95 XPAR 95,77 This has space and tabs on the second row. I would like it to look like XPAR 1, 196, 95, 77 But I always get the below because of the spaces above. , , ,1, 196 95 95,77 I use... (9 Replies)
Discussion started by: priyanka.premra
9 Replies

3. Shell Programming and Scripting

Modify a file by another file: add new line and variable after string is found

hello, I have problem with writing/adjusting a shell script. I searched forum and unfortunately couldn't write scipt based on the information I found. I never wtire such so it's hard for me and I do need to modify one script immediately. case looks like: 1. 'file' that needs to be modified... (3 Replies)
Discussion started by: bipbip
3 Replies

4. Shell Programming and Scripting

Modify line with dynamic variable in awk

Hi, I'm guessing this is probably relatively straight forward to do in awk, but I just can't get my head round it! I have a log file of the following format: 3:03:35 (lmgrd) TIMESTAMP 10/14/2011 3:20:41 (MLM) IN: "MATLAB" user1@host1.private.dns.zone 3:21:05 (MLM) IN: "MATLAB"... (2 Replies)
Discussion started by: chrissycc
2 Replies

5. UNIX for Dummies Questions & Answers

grep and modify

if input1 has an expression nouse covert allcolumns in to hashes except 6th column. ex: abc100 has no use in 3rd row and 4th row and became hashes. BUT if input1 1st column keys-1st row has no words in 3rd column (ex: def200 (key) and 1st row has no words in 3rd column (no x/x or y/y or others)... (2 Replies)
Discussion started by: ruby_sgp
2 Replies

6. Shell Programming and Scripting

Modify a file

Hi all Can anyone suggest me a good solution ? My requirement is as follows I have a plain text file similar to this... sending data to 0003345234 here is the output... ,.......... ........... ....... sending data to 00033452ab here is the output... ,.......... ........... .... (5 Replies)
Discussion started by: ./hari.sh
5 Replies

7. Shell Programming and Scripting

how to modify the value of the variable

Hi I have a variable which holds full path to the file, for example z=/bb/data3/f4222pdb.dta.new I need to remove the extension .new so it would look like z=/bb/data3/f4222pdb.dta Is there a command to do this? This variable is used in the "for" loop later. I am in ksh. Thanks a lot -A (4 Replies)
Discussion started by: aoussenko
4 Replies

8. Shell Programming and Scripting

Request to modify script to list multiple parameters for V_fieldid variable

I am posting a script below which essentially excutes the following functions in the described order. 1) From a source directory pools together three files generated by system logs for each user session, tar's these files and archives them as a log set in a destination directory and these... (0 Replies)
Discussion started by: Sammy
0 Replies

9. UNIX for Advanced & Expert Users

Modify files

Hi everybody, I have a certine file with lots of number, Which I want to add a " in the begging and at the and of each line. Could anyone tell me how can I do it? Cheers (7 Replies)
Discussion started by: amgo
7 Replies

10. Shell Programming and Scripting

modify a file

I'm a new member of the forum, I had this new generate file since I use 'grep' and 'awk', what I want to do is get rid off the all 0s before the numbers, is there any one who could help me to figure it out? Thanks a lot! yun 0000000029 000q7472 2002/03/01 0000000030 000q7472 2002/03/01 ... (2 Replies)
Discussion started by: yxiao
2 Replies
Login or Register to Ask a Question