Problem in Concatination of string in bash scripts containing back slashes.


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Problem in Concatination of string in bash scripts containing back slashes.
# 1  
Old 06-14-2012
Problem in Concatination of string in bash scripts containing back slashes.

My script is as follows:

Code:
#!/bin/bash
STR1="test"
echo $STR1
STR2="/bldtmp/"$STR1
echo $STR2
STR3=$STR2'/tmp'
echo $STR3

output i am geting
----------------
Code:
test
/bldtmp/test
/tmptmp/test

but my need is:
------------------
Code:
test
/bldtmp/test
/bldtmp/test/tmp

please help me in this?

Last edited by Scrutinizer; 06-14-2012 at 10:14 AM.. Reason: code tags
# 2  
Old 06-14-2012
Your script file is in DOS format. Try converting it to Unix format like this:
Code:
tr -d '\r' < script > newscript


Last edited by Scrutinizer; 06-15-2012 at 04:26 AM..
This User Gave Thanks to Scrutinizer For This Post:
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Bash shell script: Str(007) to int(7),increment it(8) & convert back to string(008)

Hi, I have the following requirement. There will be following text/line in a file (eg: search-build.txt) PRODUCT_VERSION="V:01.002.007.Build1234" I need to update the incremental build number (eg here 007) every time I give a build through script. I am able to search the string and get... (4 Replies)
Discussion started by: drwatson_droid
4 Replies

2. Shell Programming and Scripting

Requesting full back up scripts

hi guys linux noob here wanting to learn linux scripting, i need help with a backup script that not only allows me to back up my files but restore them to my own personal directory, had a look at some of the coding from the scripts section on this site but still lost. any help is much appreciated (8 Replies)
Discussion started by: burnie35
8 Replies

3. Homework & Coursework Questions

Date comparison with 'string date having slashes and time zone' in Bash only

1. The problem statement, all variables and given/known data: I have standard web server log file. It contains different columns (like IP address, request result code, request type etc) including a date column with the format . I have developed a log analysis command line utility that displays... (1 Reply)
Discussion started by: TariqYousaf
1 Replies

4. Shell Programming and Scripting

Changing the Bash Scripts to Bourne Scripts:URGENT

Hi, I have to write a program to compute the checksums of files ./script.sh I wrote the program using bash and it took me forever since I am a beginner but it works very well. I'm getting so close to the deadline and I realised today that actually I have to use normal Bourne shell... (3 Replies)
Discussion started by: pgarg1989
3 Replies

5. AIX

Help with back ground scripts...

I have a user that runs a menu driven application, is there a way to see what scripts this application is executing in the back ground? OS=AIX 4.3 (1 Reply)
Discussion started by: mangolinux
1 Replies

6. Solaris

Back up scripts

Hi Everyone, I would like to write a Back-up script for huge files and 3 day old file. I think i need to use Tar command for it. But I am not sure how this can be done. Can someone please assist me on this. (4 Replies)
Discussion started by: gehlnar
4 Replies

7. UNIX for Dummies Questions & Answers

Using concatination for commands

I would like to know a way that we can exec.......some thing like this from the prompt for EG when we type ftp then we could got ftp> prompt and all the ftp related commands would execute instead i need to use the ftp commands like get put from the normal user prompt it self somethinmg like... (4 Replies)
Discussion started by: pingnagan
4 Replies

8. UNIX for Dummies Questions & Answers

Executing scripts in back ground

Hi, Test1.ksh #! /bin/ksh for i in $* do #echo "$i" ksh test2.ksh $i & done test2.ksh #! /bin/ksh sleep 5s echo "From Test 1 ==> $1" exit 0; I am executing as follows: ksh test1.ksh a b c (10 Replies)
Discussion started by: risshanth
10 Replies

9. UNIX for Dummies Questions & Answers

sed command for using with back slashes

hi all, im trying to use a sed command to remove all occurenes of \p\g what i used so far is : sed 's!\p\g!!g' file but this doesnt work ? Any ideas, thanks for helping. (2 Replies)
Discussion started by: seaten
2 Replies

10. Shell Programming and Scripting

slashes in a bash shell

Substituting the / for the \ I came up with this: sed s/\\\\usr\\\\qm/\\\\\\\\qmi/g Can anyone explain to me please, why I have to pass the slash four times? :confused: (2 Replies)
Discussion started by: Shakey21
2 Replies
Login or Register to Ask a Question