Cat and variables


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers Cat and variables
# 1  
Old 09-04-2014
Cat and variables

I've been having trouble with cat and variables. If I do the following:

Code:
var1=filex
cat $var1

I get the contents of the file named filex

If I do
Code:
var2="X-0101\ 2-10-2013.txt"
cat "$var2"

I get cat : cannot open X-0101\ 2-10-2013.txt.

I have tried to do cat $var2 without quotes as well, but nothing works. The file name is X-0101\ 2-10-2013.txt. There is a space after \.

Does anyone know why this behavior? It is probably something simple. it might be associated with the whitespace, but I thought the quotes would stop that from being an issue
# 2  
Old 09-04-2014
What platform/OS are you on...
# 3  
Old 09-04-2014
Code:
cannot open X-0101\ 2-10-2013.txt.

This sounds like you have set the variable correctly. Are you sure the file is in the same directory where you're issuing this command? (Though in this case No such file or directory would appear) And are you sure you have appropriate (read) permissions on this file? (Though in this case Permission denied would appear)

Smilie
# 4  
Old 09-04-2014
version is solaris 10

Yes, I am in that directory. The version of the O/S is solaris 10.
# 5  
Old 09-04-2014
You have escaped the space character twice, once by " " and another time with \.
Try
Code:
var2="X-0101 2-10-2013.txt"

This User Gave Thanks to MadeInGermany For This Post:
# 6  
Old 09-04-2014
Thanks for the expert help!

Made in Germany, you are a GENIUS! I did what you explained, and it worked! So much pain for this simple fix!

After setting the variable as you mentioned, I then ran cat "$var2" and it worked just fine!!
# 7  
Old 09-04-2014
Sorry, I thought
Quote:
Originally Posted by newbie2010
The file name is X-0101\ 2-10-2013.txt. There is a space after \.
Just saying.
 
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

How to pass variables into anothother variables?

Below are three variables, which I want to pass into variable RESULT1 username1=userid poihostname1=dellsys.com port1=8080 How can I pass these variables into below code... RESULT1=$((ssh -n username1@poihostname1 time /usr/sfw/bin/wget --user=sam --password=123 -O /dev/null -q... (4 Replies)
Discussion started by: manohar2013
4 Replies

2. Shell Programming and Scripting

Passing awk variables to bash variables

Trying to do so echo "111:222:333" |awk -F: '{system("export TESTO=" $2)}'But it doesn't work (2 Replies)
Discussion started by: urello
2 Replies

3. Shell Programming and Scripting

Running a script with multiple variables like 25 variables.

Hi All, i have a requirement where i have to run a script with at least 25 arguements and position of arguements can also change. the unapropriate way is like below. can we achieve this in more good and precise way?? #!/bin/ksh ##script is sample.ksh age=$1 gender=$2 class=$3 . . .... (3 Replies)
Discussion started by: Lakshman_Gupta
3 Replies

4. Shell Programming and Scripting

Display variables in CAT area

Hi All, I've got a script to output YAML data, and I want to display data that's held inside variables inside one large CAT area. What's the easiest way to do this? cat << "END" --- classes: - general_image - $intro #Variable 1 - $mid #Variable 2 ... (2 Replies)
Discussion started by: glarizza
2 Replies

5. Shell Programming and Scripting

cat in the command line doesn't match cat in the script

Hello, So I sorted my file as I was supposed to: sort -n -r -k 2 -k 1 file1 | uniq > file2 and when I wrote > cat file2 in the command line, I got what I was expecting, but in the script itself ... sort -n -r -k 2 -k 1 averages | uniq > temp cat file2 It wrote a whole... (21 Replies)
Discussion started by: shira
21 Replies

6. Shell Programming and Scripting

for i in `cat myname.txt` && for y in `cat yourname.txt`

cat myname.txt John Doe I John Doe II John Doe III ----------------------------------------------------------------------- for i in `cat myname.txt` do echo This is my name: $i >> thi.is.my.name.txt done ----------------------------------------------------------------------- cat... (1 Reply)
Discussion started by: danimad
1 Replies

7. Programming

How to convert byteArray variables to HexaString variables for Linux?

Hello everybody, I am having problem in converting byte array variables to Hexa String variables for Linux. I have done, converting byte array variables to Hexa String variables for Windows but same function doesn't work for linux. Is there any difference in OS ? The code for Windows is given... (2 Replies)
Discussion started by: ritesh_163
2 Replies

8. UNIX for Dummies Questions & Answers

Difference between cat , cat > , cat >> and touch !!!

Hi Can anybody tell the difference between Difference between cat , cat > , cat >> and touch command in UNIX? Thanks (6 Replies)
Discussion started by: skyineyes
6 Replies

9. Shell Programming and Scripting

cat setting variables

hi All I have a file that has 4 lines: 1. yesterday's date (mm/dd/yyyy) 2. yesterday's day- dd 3. yesterday's month- mm 4. yesterday's year- yyyy I want to read this file and place them in variables. how can I do this. Please help. thanks in advance!! KS (3 Replies)
Discussion started by: skotapal
3 Replies
Login or Register to Ask a Question