Trying to display a tab character in variable


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Trying to display a tab character in variable
# 1  
Old 04-09-2009
Trying to display a tab character in variable

Hi,

I'm trying to figure out a way to encapsulate a tab character, or four or five space characters into a string variable to be used in my script. I'm using the bash shell.

I tried
$variablename=" <string text>"

but it didnt give me the output i wanted (output was still justified to left). I tried \t right after the first quote but it printed the \t. I also tried removing the spaces and inserting an actual tab character but got the same result.

Another thing i wondered was if anyone knew how to format a here document so that if i have a line at the end of the here statement that prompts a user to enter a number, the cursor and their input stays on that line.

Any help is appreciated, thanks in advance.
# 2  
Old 04-10-2009
You need to enclose your string in quotes when outputting it.
Code:
$ str="   <string text>"                         <<<  3 spaces included
$ echo $str
<string text>
$ echo "$str"
   <string text>
$ str="         <string text>"                   <<<  tab included 
$ echo $str
<string text>
$ echo "$str"
        <string text>
$

# 3  
Old 04-10-2009
Thanks very much, I didn't think to try that.

Anyone know how to keep the cursor on the line in the here statement?
# 4  
Old 04-10-2009
Quote:
Originally Posted by rowlf
Thanks very much, I didn't think to try that.

Anyone know how to keep the cursor on the line in the here statement?
please elaborate - this is too vague.
# 5  
Old 04-10-2009
try one of these:

echo -n alskdhfalkshdf
print -n alkshdlkfhaslhdf
echo aklsdlhfaskdf\c
# 6  
Old 04-10-2009
Quote:
Originally Posted by vgersh99
please elaborate - this is too vague.
I had a more elaborate description of the problem in my original post.

I have a 'here' statement in my program.

Code:
cat <<thenameoftheHERE
 
 
thenameoftheHERE

which is supposed to print to screen whatever i type between the two statements formatted exactly as i type it. My final formatted piece of text is prompting the user to enter a number, like this:

Please enter a number:


but the cursor is going two lines down and justified with the left margin and i want the cursor and the number to appear right after the colon in the prompt statement like this:

Please enter a number: 5

Thanks for any help
# 7  
Old 04-10-2009
leave everything but the final "Please enter a number: " in the HERE document.

Then use:

print -n "Please enter a number: "
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Passing literal tab character from zsh to other program

I have a Zsh script which invokes another program. One of the paramters to be passed, should be a literal tab, i.e what in common programming languages is often written as "\t". If it were bash, I think I could use the special form $"\t" but this doesn't seem to work (the called program... (5 Replies)
Discussion started by: rovf
5 Replies

2. Shell Programming and Scripting

[Solved] SED - Bash - Inserting multi Tab character in the command

Hello. I am using : sed -i -e '/§name_script§/a#'"${MY_TAB11}"'# \ #'"${MY_TAB1}"'The Standard way'"${MY_TAB7}"'# \ #'"${MY_TAB1}"'==============='"${MY_TAB7}"'# \ ' "$CUR_FILE" Is there a better way to define "MY_TAB7","MY_TAB11" in other way than : MY_TAB1=$'\t' MY_TAB2=${MY_TAB1}$'\t'... (2 Replies)
Discussion started by: jcdole
2 Replies

3. UNIX for Dummies Questions & Answers

Remove tab character from file

I am trying to remove the tab character from a file, which occurs on two places in every line. So far I have tried the following and most are from threads in this forum: sed -i '' -e 's/ / /' file.dat sed -i '' -e 's/*/ /' file.dat sed -i '' -e 's/\t*/ /g' file.dat sed -i '' -e 's/*//g'... (4 Replies)
Discussion started by: figaro
4 Replies

4. UNIX for Dummies Questions & Answers

Display last 8 character of filename

I would like to display the last 8 characters of the filenames for filenames of different lengths. I can delete the last 8 characters with sed but dont know how to only show the last 8 characters. The filenames are something like; afxH340800340000 afxH30800340021 afxR3080034002122 I... (3 Replies)
Discussion started by: Beanz
3 Replies

5. Shell Programming and Scripting

Delete parts of a string of character in one given column of a tab delimited file

I would like to remove characters from column 7 so that from an input file looking like this: >HWI-EAS422_12:4:1:69:89 GGTTTAAATATTGCACAAAAGGTATAGAGCGT U0 1 0 0 ref_chr8.fa 6527777 F DD I get something like that in an output file: ... (13 Replies)
Discussion started by: matlavmac
13 Replies

6. Shell Programming and Scripting

Display of string with TAB in it

Hi, I am having trouble using the result of the following awk command in a script, as displaying the contents of the placeholder automatically replaces the new created TAB by a space character again: From the prompt: cscyabl@comet:(develop)> echo "01 12" | awk '{gsub(" ","\t");print}' 01 ... (2 Replies)
Discussion started by: Indalecio
2 Replies

7. Shell Programming and Scripting

why convert 8 space to 1 tab character on unix?

Hi everybody, I'm using Hp unix tru64. I have generate one file from shell script. bus that file content pre "8 space char" convert one tab character. why? result file hex format: hex 20 20 20 20 20 to 09 (6 Replies)
Discussion started by: Tlg13team
6 Replies

8. UNIX for Advanced & Expert Users

newline character, space and tab after a string

no problem (6 Replies)
Discussion started by: angelina
6 Replies

9. UNIX for Dummies Questions & Answers

read a variable character by character, substitute characters with something else

im having trouble doing this: i have a variable with 2 characters repeating e.g. aababbbaaaababaabbaabbba is there a way i can search the variable for a's and b's and then change a's to b's and b's to a's? im guessing its like getting the 1's compliment of the string im doing this in... (2 Replies)
Discussion started by: vipervenom25
2 Replies

10. Shell Programming and Scripting

how to display only last character of a string?

hi all, if i do an: "echo $string |" what should be after the pipe to display ONLY the last char of the output? tia, DN2 (9 Replies)
Discussion started by: DukeNuke2
9 Replies
Login or Register to Ask a Question