Sponsored Content
Top Forums Shell Programming and Scripting Help setting variable from file contents with spaces Post 302367409 by nrogers64 on Monday 2nd of November 2009 01:35:08 PM
Old 11-02-2009
Question Help setting variable from file contents with spaces

I suppose the easiest way to explain my problem is to show you some code and then show you what the code outputs:

--------------------------------------------------
#!/bin/bash
echo "This line has spaces" > "/tmp/This Filename Has Spaces.txt"

export Foo=$(cat "/tmp/This Filename Has Spaces.txt")

VarName=Bar
export $VarName=$(cat "/tmp/This Filename Has Spaces.txt")

echo $Foo
echo $Bar
--------------------------------------------------

This is the output:

This line has spaces
This

How do I get the "Bar" variable to output the full string?

Thanks so much!
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Remove spaces from first field, and write entire contents into other text file

Hi all, I have searched and found various threads about removing spaces from a field within a text file. Unfortunately, I have not found exactly what I'm looking for, nor am I adept enough to modify what I've found into what I need. I use the following command to remove the first line... (3 Replies)
Discussion started by: carriehoff
3 Replies

2. Shell Programming and Scripting

Storing the contents of a file in a variable

There is a file named file.txt whose contents are: +-----------------------------------+-----------+ | Variable_name | Value | +-----------------------------------+-----------+ | Aborted_clients | 0 | | Aborted_connects | 25683... (6 Replies)
Discussion started by: proactiveaditya
6 Replies

3. Shell Programming and Scripting

Read the contents of a file and store them in a variable

Hi Gurus, I am trying for a scenario where in I want to read the contents of a file line by line and then store them in variables. Below is the script: #!/bin/ksh while read line do id=`echo $line | cut -f1 -d |` name=`echo $line | cut -f2 -d |` echo $id ... (11 Replies)
Discussion started by: svajhala
11 Replies

4. Shell Programming and Scripting

How to read contents of a file into variable :(

My file is in this format : username : student information : default shell : student ID Eg : joeb:Joe Bennett:/bin/csh:1234 jerryd:Jerry Daniels:/bin/csh:2345 deaverm: Deaver Michelle:/bin/bash:4356 joseyg:Josey Guerra:/bin/bash:8767 michaelh:Michael Hall:/bin/ksh:1547 I have to... (1 Reply)
Discussion started by: dude_me5
1 Replies

5. Homework & Coursework Questions

How to read contents of a file into variable :(

Use and complete the template provided. The entire template must be completed. If you don't, your post may be deleted! 1. The problem statement, all variables and given/known data: I have to read the contents of each field of a file creating user accounts. The file will be of format : ... (6 Replies)
Discussion started by: dude_me5
6 Replies

6. Shell Programming and Scripting

Folder contents getting appended as strings while redirecting file contents to a variable

Hi one of the output of the command is as below # sed -n "/CCM-ResourceHealthCheck:/,/---------/{/CCM-ResourceHealthCheck:/d;/---------/d;p;}" Automation.OutputZ$zoneCounter | sed 's/$/<br>/' Resource List : <br> *************************** 1. row ***************************<br> ... (2 Replies)
Discussion started by: vivek d r
2 Replies

7. Shell Programming and Scripting

Select command with variable options having spaces or null contents

Hi, I'm having an issue trying to produce a hierarchical directory menu that has either any directories listed in a specific directory as options or options with spaces in the option content or null content. So the menu function gets passed a base directory, it then lists any .sh scripts in... (6 Replies)
Discussion started by: andyatit
6 Replies

8. Shell Programming and Scripting

Echo variable contents into a text file...

Hi all, I am trying to create a script to read my Windows UUIDs and create mounts in fstab. I know there are different and maybe even better ways to mount Windows partitions at boot time, but I always manually create them in fstab successfully. I do a clean install of Ubuntu often and would like to... (2 Replies)
Discussion started by: Ian Pride
2 Replies

9. UNIX for Dummies Questions & Answers

HTML: Display contents of file using Variable

<tr><td bgcolor=#D7EBAD><b>Instructions :</b></td> <td>`cat temp.txt`</td></tr> Hi Experts, I have an requirement of displaying file contents in HTML mail , for which am using the above approach, Where as the output is kind of not as expected. If there are 5 lines in the file, in the... (4 Replies)
Discussion started by: scott_cog
4 Replies

10. UNIX for Beginners Questions & Answers

Storing file contents to a variable

Hi All, I was trying a shell script. I was unable to store file contents to a variable in the script. I have tried the below but unable to do it. Input = `cat /path/op.diary` Input = $(<op.diary) I am using ksh shell. I want to store the 'op.diary' file contents to the variable 'Input'... (12 Replies)
Discussion started by: am24
12 Replies
Perl::Critic::Policy::Modules::RequireFilenameMatchesPacUser(Contributed Perl DocPerl::Critic::Policy::Modules::RequireFilenameMatchesPackage(3pm)

NAME
Perl::Critic::Policy::Modules::RequireFilenameMatchesPackage - Package declaration must match filename. AFFILIATION
This Policy is part of the core Perl::Critic distribution. DESCRIPTION
The package declaration should always match the name of the file that contains it. For example, "package Foo::Bar;" should be in a file called "Bar.pm". This makes it easier for developers to figure out which file a symbol comes from when they see it in your code. For instance, when you see "Foo::Bar->new()", you should be able to find the class definition for a "Foo::Bar" in a file called Bar.pm Therefore, this Policy requires the last component of the first package name declared in the file to match the physical filename. Or if "#line" directives are used, then it must match the logical filename defined by the prevailing "#line" directive at the point of the package declaration. Here are some examples: # Any of the following in file "Foo/Bar/Baz.pm": package Foo::Bar::Baz; # ok package Baz; # ok package Nuts; # not ok (doesn't match physical filename) # using #line directives in file "Foo/Bar/Baz.pm": #line 1 Nuts.pm package Nuts; # ok package Baz; # not ok (contradicts #line directive) If the file is not deemed to be a module, then this Policy does not apply. Also, if the first package namespace found in the file is "main" then this Policy does not apply. CONFIGURATION
This Policy is not configurable except for the standard options. AUTHOR
Chris Dolan <cdolan@cpan.org> COPYRIGHT
Copyright (c) 2006-2011 Chris Dolan. This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself. perl v5.14.2 2012-06-07 Perl::Critic::Policy::Modules::RequireFilenameMatchesPackage(3pm)
All times are GMT -4. The time now is 12:39 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy