Sponsored Content
Top Forums Shell Programming and Scripting [BASH] Getting a semi-tailing backslash when passing (escaped) variables to script Post 302942481 by sea on Wednesday 29th of April 2015 07:41:56 AM
Old 04-29-2015
Added single quotes, and removed the escape chars from that named if block.
And yes, that $Q was/is an option : -q, sry forgot to mention.

During the writing of tui-cat, i've added a code block to tui-printf (the very core display command) which escaped tailing backslashes, you know, to keep them when using tui-cat, and not get them changed to one-liners...
Seems that function also jumped in as soon the strings contained dollars/variables. Though, it seemed to only add a single backslash at the end of the string.
tui-printf:
Code:
	# Escape trailing backslash, from whichever argument passed
	# This is supposed to 'keep' artificial linebreaks rather than get them on one line
	echo "$FIRST" | grep -q "\\"$ && \
		FIRST="${FIRST}\\\\"
	echo "$SECOND" | grep -q "\\"$ && \
		SECOND="${SECOND}\\\\"
	echo "$THIRD" | grep -q "\\"$ && \
		THIRD="${THIRD}\\\\"
	
	# Escape '%'
	...

So it seems now, that i need something else to preserve articifical linebreaks, but not add unrequred baskslashes to strings with variables...
How to define that $ is supposed to be the line end only, but not a variable indicator at all?
Kind of helpless, as i though the above code whould do so...

Thank you

---------- Post updated at 13:41 ---------- Previous update was at 12:52 ----------

Guess i solved it, at least for this one time test it worked:
Changed it to:
Code:
        [ "\\" = "${FIRST:0:(-1)}" ] && \
                FIRST="${FIRST}\\"

Thank you
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

problems with sed and bash. Escaped characters ?

Hi, I'm writing a long script for bash (on RHEL 5.0) to execute many commands. So, my idea is to create a function to deal with error checking and logging (see ceckoutput() below). This works with all commands except for sed. I think it may be a problems with escaped characters. So I did the... (4 Replies)
Discussion started by: macL
4 Replies

2. Shell Programming and Scripting

bash - add backslash in front of variables w/ spaces

Hello, Im writing a script that works by recursively going into directories with find. But I have some directories that have spaces in them.. so I need to parse the variables to add a backslash before the spaces. Im not exactly sure how how to do this in bash, and honestly I dont think I know... (3 Replies)
Discussion started by: trey85stang
3 Replies

3. Shell Programming and Scripting

Passing variables problem - Bash

I have a following problem: #!/bin/bash NUM=`cat accounts | wc -l`; for i in {1..$NUM} do account=`awk "NR==$i" accounts`; echo -e "\nAccount: $account\n"; sudo ./backup_maildir $account; done "accounts" is a file with regular e-mail addresses, one in each line.... (2 Replies)
Discussion started by: bobanpetrovic
2 Replies

4. Shell Programming and Scripting

passing double backslash(\\) as a path in unix

Hi All, I am trying to add a tag in the *.imp file. This is a piece of code which I am giving in my template file and my script reads this template file attachment and passes to windows server(as they have provided the below file path). ... (3 Replies)
Discussion started by: defendersubbu
3 Replies

5. Shell Programming and Scripting

Passing variables from bash to php-cli

Hello everyone, I've been looking how to pass variables between bash and php-cli in 1 file. So far i got this: #!/bin/bash echo "This is bash" php << EOF <?php echo "This is php\n"; ?> EOF I would now like to be able to pass a variable declared in the bash to the php. I already... (0 Replies)
Discussion started by: robbee
0 Replies

6. Shell Programming and Scripting

Passing backslash character to awk variable

Hi All. I have a file that contains some special characters and I'm trying to use AWK to search for lines between <pattern1> and <pattern2>. As an example: I need the lines between the line containing ' select_id="x_0 ' and the line containing the next instance of ' from '. This is a file... (5 Replies)
Discussion started by: Mudshark
5 Replies

7. UNIX for Dummies Questions & Answers

Using read with escaped variables

Not sure if this is possible, but I'm trying to read in a variable that needs to have its escape backslashes intact. So the person who enters the actual value does not have to type any \ characters. Example: read list X1000\ filecab.txt echo "$list" In this case the \ needs to be... (3 Replies)
Discussion started by: newbie2010
3 Replies

8. 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

9. Shell Programming and Scripting

Passing variables from one script to another

Hi, this is the example i'm trying to do. script1.sh ABC="test.txt" ./script2.sh "$ABC" script2.sh INPUT="$HOMEDIR/$ABC" echo $INPUT when i run the 1st script it gives me ../home/ the test.txt is not passed into 2nd script. How can i resolve this. (2 Replies)
Discussion started by: gskris88
2 Replies

10. Shell Programming and Scripting

[Bash] passing variables to executable doesn't work

Bash version 4.4.20 / Ubuntu 16.0.4 Hello, I tried to write a script that gathers some data and passes them to an executable. The executed application answers with an error. The echo output in the script returns correct values. If I copy/paste the last echo command, it get's executed... (2 Replies)
Discussion started by: sushi2k7
2 Replies
VCONSOLE.CONF(5)						   vconsole.conf						  VCONSOLE.CONF(5)

NAME
vconsole.conf - configuration file for the virtual console SYNOPSIS
/etc/vconsole.conf DESCRIPTION
The /etc/vconsole.conf file configures the virtual console, i.e. keyboard mapping and console font. The basic file format of the vconsole.conf is a newline-separated list environment-like shell-compatible variable assignments. It is possible to source the configuration from shell scripts, however, beyond mere variable assignments no shell features are supported, allowing applications to read the file without implementing a shell compatible execution engine. Note that the kernel command line options vconsole.keymap=, vconsole.keymap.toggle=, vconsole.font=, vconsole.font.map=, vconsole.font.unimap= may be used to override the console settings at boot. Depending on the operating system other configuration files might be checked for configuration of the virtual console as well, however only as fallback. OPTIONS
The following options are understood: KEYMAP=, KEYMAP_TOGGLE= Configures the key mapping table of for they keyboard. KEYMAP= defaults to us if not set. The KEYMAP_TOGGLE= can be used to configured a second toggle keymap and is by default unset. FONT=, FONT_MAP=, FONT_UNIMAP= Configures the console font, the console map and the unicode font map. FONT= defaults to latarcyrheb-sun16. EXAMPLE
Example 1. German keyboard and console /etc/vconsole.conf: KEYMAP=de-latin1 FONT=latarcyrheb-sun16 SEE ALSO
systemd(1), loadkeys(1), setfont(8), locale.conf(5) AUTHOR
Lennart Poettering <lennart@poettering.net> Developer systemd 10/07/2013 VCONSOLE.CONF(5)
All times are GMT -4. The time now is 10:54 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy