Sponsored Content
Top Forums Shell Programming and Scripting bash - add backslash in front of variables w/ spaces Post 302254594 by trey85stang on Tuesday 4th of November 2008 09:31:24 PM
Old 11-04-2008
Quote:
Originally Posted by bakunin
Thanks $deity this conclusion is wrong. Just enclose your variable content in double quotes to protect the content:

Code:
myvar="File 1/File 2/this is my file.txt"

and pass it this way:

Code:
subfunc "$myvar"

inside the function (or the external script, its the same for that matter) use it also protected. Example:

Code:
function subfunc
{
local myvar="$1"      # notice the double quotes

some_command "$some_path/$myvar" another_arg

return 0
}

I hope this helps.

bakunin

Thanks for the suggestions. I am unable to try it at this moment... since myvar is in a loop being generated by the find command. How could I go about adding the double quotes to it?
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

sh, ksh: command to remove front spaces from a string?

dear pro-coders, is there any command out there that takes out the front spaces from a string? sample strings: 4 members 5 members 3 members but it has to be like so: 4 members 5 members 3 members (3 Replies)
Discussion started by: pseudocoder
3 Replies

2. Shell Programming and Scripting

How to use backslash and variables in sed

I have a line that contains backslashes in which I want sed to substitute text with variables. The line; \\s008\2033330user$ I want to change this in \\s008.ourschool.com\2033330user$ I now use this script: USER=2033330user sed 's/\\'"$USER"'/.ourschool.com\\'"$USER/" This doesn't... (3 Replies)
Discussion started by: Tubbie
3 Replies

3. Shell Programming and Scripting

How to replace spaces excluding those within double quotes and after backslash?

In bash or perl, I would like to know how to substitute a null character (0x00) for every white space without changing the white spaces inside the block of double quotes and the white space immediately following a backslash. Suppose that sample.txt consists of the following line. "b 1" c\ 2 ... (2 Replies)
Discussion started by: LessNux
2 Replies

4. Shell Programming and Scripting

Adding a backslash in front of square brackets with sed

I'm trying to convert this line: to \ with sed. This is what I have so far: sed -e 's/\]*\)\]/\\\\\/' but this still gives me . Any suggestions? (15 Replies)
Discussion started by: lehaste
15 Replies

5. Shell Programming and Scripting

Perl: backslash in front of integer like \32768

In Perl, what does a backslash preceding an integer do like \32768 ? The $/ section of perlvar writes: local $/ = \32768; # or \"32768", or \$var_containing_32768 How is \32768 different from just 32768 without backslash? I do not understand the backslashes in \"32768" and... (1 Reply)
Discussion started by: LessNux
1 Replies

6. Linux

How to add \ in front of $ in a script with vi?

Please help to provide command in vi to add \ in front of $ so it does not interpret next character. rm interfaces/DART/WEB-INF/classes/DART/util/TotalDisconnectUtil$1.class rm interfaces/DART/WEB-INF/classes/DART/util/TotalDisconnectUtil$2.class rm... (3 Replies)
Discussion started by: ywu081006
3 Replies

7. Shell Programming and Scripting

Add text in front of variable

I am just trying to add specific text in front of a ${variant} but can not seem to get the syntax correct. I have tried sed -i '$a NM_004004.5' ${variant} and printf "NM_004004.5:%s\n" ${variant} with no luck. Thank you :). (7 Replies)
Discussion started by: cmccabe
7 Replies

8. Shell Programming and Scripting

[BASH] Getting a semi-tailing backslash when passing (escaped) variables to script

Heyas Figured me had a 'typo' in tui-conf-set, i went to fix it. Now, i also figured, it might be nice to have tui-conf-set report (to console, not only exit code) wether it could save the variable to the file or not. This said, I appended this code: (the tui-title and tui-echo lines are... (3 Replies)
Discussion started by: sea
3 Replies

9. Shell Programming and Scripting

[sed]: syntax to insert N spaces in front of a string

Dear all, I would like to insert N blankspaces in front of a string using sed command To give an example (N=10), I tried that code: $ echo "abcd" | sed 's/^/ \{10,\}&/' but I failed, by obtaining that result: {10,}abcd Any help would be greatly appreciated, Thanks in advance,... (18 Replies)
Discussion started by: dae
18 Replies

10. Shell Programming and Scripting

Add backslash and apostrophe to string in variable.

Hi All I want to add backslash and apostrophe to variable in my bash script. I have my variable: USER_LIST=USER1,USER2,USER3 and I want something like this: USER_LIST_DEL=/'USER1/',/'USER2/',/'USER3/' any ideas ?? (1 Reply)
Discussion started by: primo102
1 Replies
Template::Plugin::YAML(3pm)				User Contributed Perl Documentation			       Template::Plugin::YAML(3pm)

NAME
Template::Plugin::YAML - Plugin interface to YAML SYNOPSIS
[% USE YAML %] [% YAML.dump(variable) %] [% YAML.dump_html(variable) %] [% value = YAML.undump(yaml_string) %] [% YAML.dumpfile(filename, variable) %] [% value = YAML.undumpfile(filename) %] DESCRIPTION
This is a simple Template Toolkit Plugin Interface to the YAML module. A YAML object will be instantiated via the following directive: [% USE YAML %] As a standard plugin, you can also specify its name in lower case: [% USE yaml %] METHODS
These are the methods supported by the YAML object. dump( @variables ) Generates a raw text dump of the data structure(s) passed [% USE Dumper %] [% yaml.dump(myvar) %] [% yaml.dump(myvar, yourvar) %] dump_html( @variables ) Generates a dump of the data structures, as per "dump", but with the characters <, > and & converted to their equivalent HTML entities, spaces converted to &nbsp; and newlines converted to <br>. [% USE yaml %] [% yaml.dump_html(myvar) %] undump( $string ) Converts a YAML-encoded string into the equivalent data structure. Here's a way to deep-copy a complex structure by completely serializing the data. [% USE yaml; yaml_string = yaml.dump(complex_data_structure); complex_copy = yaml.undump(yaml_string); %] dumpfile( $file, @variables ) Converts the data to YAML encoding, and dumps it to the specified filepath. [% USE yaml; yaml.dumpfile(".storage", my_data) %] undumpfile( $file ) Loads the YAML-encoded data from the specified filepath [% USE yaml; my_data = yaml.undumpfile(".storage") %] AUTHORS
Richard Clamp <richardc@unixbeard.net>, with undump, undumpfile, and dumpfile implementation by Randal L. Schwartz <merlyn@stonehenge.com> based on Simon Matthews' Template::Plugin::Dumper COPYRIGHT
Copyright 2003, 2008 Richard Clamp All Rights Reserved. This module is free software; you can redistribute it and/or modify it under the same terms as Perl itself. SEE ALSO
Template::Plugin::Dumper perl v5.10.0 2008-12-15 Template::Plugin::YAML(3pm)
All times are GMT -4. The time now is 04:41 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy