Sponsored Content
Top Forums UNIX for Advanced & Expert Users Without the aid of the escape mechanism, how to put a raw string into a variable? Post 303045751 by wisecracker on Sunday 12th of April 2020 05:23:57 AM
Old 04-12-2020
Without the aid of the escape mechanism, how to put a raw string into a variable?

Hi guys and gals...
I have been racking my brains with this one and I can't find anything about it...
Consider the code and the results below:
Code:
#!/usr/local/bin/dash

# #!/bin/sh
# #!/bin/bash
# rawstring.sh

: > /tmp/rawstring

# ############# THIS WORKS ADMIRABLY! ##############
NUM=32
STRING=""

while [ ${NUM} -le 126 ]
do
    printf \\$( printf "%03o" "${NUM}" ) >> /tmp/rawstring
    NUM=$(( NUM + 1 ))
done

STRING=$( cat /tmp/rawstring )
echo ""
/bin/echo "${STRING}"
echo ""
echo "${STRING}"
# ########## END OF THIS WORKS ADMIRABLY! ##########

# ##################################################
# THIS HOWEVER FAILS CATASTROPHICALLY!
echo ""
echo "This is where the error is with or without leading and trailing"
echo "single or double quotes:-"
echo ""

STRING=' !"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_`abcdefghijklmnopqrstuvwxyz{|}~'

# The line below does not even get executed!
echo "${STRING}"
# ##################################################

Results on OSX 10.14.x:
Code:
Last login: Sun Apr 12 09:52:48 on ttys000
AMIGA:amiga~> cd Desktop/Code/Shell
AMIGA:amiga~/Desktop/Code/Shell> ./rawstring.sh

 !"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_`abcdefghijklmnopqrstuvwxyz{|}~

 !"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_`abcdefghijklmnopqrstuvwxyz{|}~

This is where the error is with or without leading and trailing
single or double quotes:-

./rawstring.sh: 33: ./rawstring.sh: Syntax error: "(" unexpected
 AMIGA:amiga~/Desktop/Code/Shell> _

As you can see saving a rawstring to disk and retrieving it again works but trying to force a rawstring without the escape mechanism fails catastrophically.
This is one of the USEFUL uses of 'cat' as it works admirably in this case but it requires I/O to do so...
I need to avoid the use of the escape mechanism inside the failing condition in case I want to __edit__ said rawstring inside any code.

I would like to know what is different about putting a rawstring into a variable using 'cat' and attempting to do so using hard coding.


Bazza...
 

8 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Put raw data to column data

Dear all, I want below data to make it in column format.so i will see the data like this cdrID teleServiceCode chargedPartyNumber ... ... ... ... "egmailcom0w10ggzx00" 'sMS (5)' "716323770" "m17ifi5z30w0z6o7200" 'sMS (5)' ... (7 Replies)
Discussion started by: Nayanajith
7 Replies

2. UNIX for Advanced & Expert Users

Remove escape characters from string

Hello all, I have a string var which contains formatting characters at the end, it is a string with EScape sequences at the end of it. How can I remove them so that I only keep the 'real' text? I tried : var1=${var1%%\033[0m} does not seem to do the job .... Please help Thanks (2 Replies)
Discussion started by: gio001
2 Replies

3. Programming

how to use hex escape char with string in C?

I want it to ouput "abcd", but it dosen't. 1 #include<stdio.h> 2 int main() 3 { 4 printf("a\x62cd"); 5 } 6 gcc alarm.c -o alarm alarm.c: In function 'main': alarm.c:4:9: warning: hex escape sequence out of range It seems that the complier joint "cd" as part of... (8 Replies)
Discussion started by: vistastar
8 Replies

4. Shell Programming and Scripting

awk not escape my bash variable

I tried to parse data from switch configuration files vlan 1727 name SQ5506-15 by port tagged ethe 8/1 to 8/2 untagged ethe 1/13 ! vlan 2105 name SQ5620-7007(BR2) by port tagged ethe 8/1 to 8/2 untagged ethe 1/17 ! interface ethernet 1/13 port-name SQ5506-15.nic0 rate-limit... (2 Replies)
Discussion started by: winggundamth
2 Replies

5. Shell Programming and Scripting

How to store a escape character in a Variable.?

How to store escape character in the variable. Var=abc,def,ghi,jkl echo ${Var} | sed -e "s/,/|\\\\./g;s/^/\\\\./g" \.abc|\.def|\.ghi|\.hjk Var1=`echo ${Var} | sed -e "s/,/|\\\./g;s/^/\\\./g"` Actual: ------- echo $Var1 .abc|.def|.ghi|.jkl Expected: --------- echo $Var1... (4 Replies)
Discussion started by: deepakwins
4 Replies

6. UNIX for Beginners Questions & Answers

String has * as the field delimiter and I need echo/awk to escape it, how?

Hi, I am trying to read an Oracle listener log file line by line and need to separate the lines into several fields. The field delimiter for the line happens to be an asterisk. I have the script below to start with but when running it, the echo command is globbing it to include other... (13 Replies)
Discussion started by: newbie_01
13 Replies

7. Shell Programming and Scripting

How to escape colon sign from variable in shell?

Hello, Below script works fine when I manually enter required information for each file. When it comes to shell in auto mode, it gives various errors. I am under ubuntu 14.04 / trusty. manual_run.sh: #!/bin/bash /usr/bin/ffmpeg -start_at_zero -copyts -i nicki.mp4 -c:v mpeg2video \ -b:v 500k... (3 Replies)
Discussion started by: baris35
3 Replies

8. Shell Programming and Scripting

Escape characters in a variable

Debian 9 64x - LXDE How can i disable escape sequences in a variable? #!/bin/bash #mainscript . "./links.bash" echo "$red_start This text should be red $color_end"#!/bin/bash #links.bash #colors red_start="\eOutput that i get: \e Output expected: This text should be... (5 Replies)
Discussion started by: int3g3r
5 Replies
RG::Blast::Parser(3pm)					User Contributed Perl Documentation				    RG::Blast::Parser(3pm)

NAME
RG::Blast::Parser - fast NCBI BLAST parser SYNOPSIS
use Data::Dumper; use RG::Blast::Parser; my $parser = RG::Blast::Parser->new(); # read from STDIN open( EXAMPLE, '<', '/usr/share/doc/librg-blast-parser-perl/examples/converged.ali' ) || confess($!); my $parser = RG::Blast::Parser->new( *EXAMPLE, "converged.ali" ); # read from EXAMPLE, use name "converged.ali" in error messages while( my $res = $parser->parse() ) { print Dumper( $res ); } eval { my $res = $parser->parse(); # ... }; if( $@ && $@ =~ /^parser error/ ) { warn("failed to parse blast result - exception caught"); } DESCRIPTION
This package contains perl binding for a very fast C/C++ library for NCBI BLAST -m 0 (default) output parsing. BLAST results are returned in a convenient hash structure. Multiple results may be concatenated for input. One result is parsed and returned at a time. CONSTRUCTOR
new( [FILEHANDLE, [NAME]] ) Creates an "RG::Blast::Parser". Blast results are read from FILEHANDLE, STDIN by default. The input stream may be named NAME in error messages (default: "STDIN"). METHODS
parse( [TRACE_PARSING, [TRACE_SCANNING]] ) Parse one complete BLAST result and return it. If no results on input stream, returns "undef". In case of parser error it die()s with an (at present not very useful) error message. The following structure is returned in a hash reference: { blast_version => STRING, references => [ STRING, ... ], rounds => [ { oneline_idx => NUM, # index of first one-line description of # round in "onelines" oneline_cnt => NUM, # number of one-line descriptions of round # in "onelines" hit_idx => NUM, # index of first hit of round in "hits" hit_cnt => NUM, # number of hits of round in "hits" oneline_new_idx => NUM|undef# index of first new (not-seen-before) # one-line description of round oneline_new_cnt => NUM # number of new one-line descriptions of # round }, ... ], q_name => STRING, q_desc => STRING|undef, q_length => NUM, db_name => STRING, db_nseq => NUM, db_nletter => NUM, onelines => [ # one-line descriptions from all rounds { name => STRING, desc => STRING|undef, bit_score => NUM, e_value => NUM }, ... ], converged => BOOLEAN, hits => [ # hits from all rounds { name => STRING, desc => STRING|undef, length => NUM, hsps => [ { bit_score => NUM, raw_score => NUM, e_value => NUM, method => STRING, identities => NUM, positives => NUM, gaps => NUM, q_strand => STRING|undef, s_strand => STRING|undef, q_frame => NUM|undef, s_frame => NUM|undef, q_start => NUM, q_ali => STRING, q_end => NUM, match_line => STRING, s_start => NUM, s_ali => STRING, s_end => NUM }, ... ] }, ... ], tail => STRING # bulk text after the last hit / one-line # description } If you want tracing for parsing and scanning, you can enable them using the parameters of this call. result() Returns the last BLAST result parsed or "undef" if no last result. get_trace_scanning() Returns scan trace state as a Boolean value. set_trace_scanning( BOOLEAN ) Set scan trace - debugging aid. SEE ALSO
Zerg(3pm), Zerg::Report(3pm) AUTHOR
Laszlo Kajan, <lkajan@rostlab.org> COPYRIGHT AND LICENSE
Copyright (C) 2012 by Laszlo Kajan This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself, either Perl version 5.8.8 or, at your option, any later version of Perl 5 you may have available. perl v5.14.2 2012-03-29 RG::Blast::Parser(3pm)
All times are GMT -4. The time now is 02:30 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy