LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (http://www.linuxquestions.org/questions/programming-9/)
-   -   bash printing extended ASCII characters (http://www.linuxquestions.org/questions/programming-9/bash-printing-extended-ascii-characters-286242/)

nutthick 02-04-2005 01:44 PM

bash printing extended ASCII characters
 
I'm trying to print ? ? ? and other extended ascii character in bash using printf, but they don't seem to be regonised. The syntax I'm using is

printf "\###"

where ### is the octal value for the character.

Does anyone know if extended ascii is supported in bash and if so how to print the characters to the screen?

Thanks

keefaz 02-04-2005 01:50 PM

That depends a little of the font used in terminal (what do you call extended ascii ?)

Try (in hexa) :
echo -e "\xA9"

and in octal :
echo -e "\0251"

nutthick 02-04-2005 01:57 PM

I've been programming for a few years and I never knew that 'extended ascii' was so ambiguous, but now I've done some reading I realise there is no such thing.

When I say extended ascii, I guess I mean IBM DOS extended ascii. Have a look at

http://www.lookuptables.com/

there is some 'extended ascii' at the bottom.

keefaz 02-04-2005 02:04 PM

Lol, I see... For me this is just ascii (but I don't program for a few years, just the last one)

I would say again that the display of these chars depends of the terminal font, eg if the char
won't display, it may means that this char is not built in the font.

nutthick 02-04-2005 02:10 PM

I've been reading something about codepage. That might have something to do with it. bash has something there about 127, I'm just doing a script to find out what it is, I'll let you know.

nutthick 02-04-2005 02:22 PM

Well nothing too good. Below is a list of the ascii code outputs through printf from 0 to 400. The left column is the octal code, the right is the output. Hope this helps someone out, because it helped me squat ;)

0
1 
2 
3 
4 
5 
6 
7 
8 \8
9 \9
10 
11
12

13
14
15
16 
17 
18 8
19 9
20 
21 
22 
23 
24 
25 
26 
27 
28 8
29 9
30 
31 
32 
33 
34 
35 
36 
37 
38 8
39 9
40
41 !
42 "
43 #
44 $
45 %
46 &
47 '
48 8
49 9
50 (
51 )
52 *
53 +
54 ,
55 -
56 .
57 /
58 8
59 9
60 0
61 1
62 2
63 3
64 4
65 5
66 6
67 7
68 8
69 9
70 8
71 9
72 :
73 ;
74 <
75 =
76 >
77 ?
78 8
79 9
80 \80
81 \81
82 \82
83 \83
84 \84
85 \85
86 \86
87 \87
88 \88
89 \89
90 \90
91 \91
92 \92
93 \93
94 \94
95 \95
96 \96
97 \97
98 \98
99 \99
100 @
101 A
102 B
103 C
104 D
105 E
106 F
107 G
108 8
109 9
110 H
111 I
112 J
113 K
114 L
115 M
116 N
117 O
118 8
119 9
120 P
121 Q
122 R
123 S
124 T
125 U
126 V
127 W
128
8
129
9
130 X
131 Y
132 Z
133 [
134 \
135 ]
136 ^
137 _
138 8
139 9
140 `
141 a
142 b
143 c
144 d
145 e
146 f
147 g
148 8
149 9
150 h
151 i
152 j
153 k
154 l
155 m
156 n
157 o
158
8
159
9
160 p
161 q
162 r
163 s
164 t
165 u
166 v
167 w
168 8
169 9
170 x
171 y
172 z
173 {
174 |
175 }
176 ~
177 
178 8
179 9
180 80
181 81
182 82
183 83
184 84
185 85
186 86
187 87
188 88
189 89
190 90
191 91
192 92
193 93
194 94
195 95
196 96
197 97
198 98
199 99
200
201 ?
202
203
204
205
206
207
208 8
209 9
210
211
212
213
214
215 ?
216
217 ?
218 8
219 9
220 ?
221
222
223
224
225
226
227
228 8
229 9
230
231
232
233
234
235 ?
236
237
238 8
239 9
240 _
241
242
243
244
245
246
247
248 8
249 9
250
251
252
253
254
255 _
256
257
258 8
259 9
260
261
262
263
264
265
266
267
268 8
269 9
270
271
272
273
274
275
276
277
278 8
279 9
280 80
281 81
282 82
283 83
284 84
285 85
286 86
287 87
288 88
289 89
290 90
291 91
292 92
293 93
294 94
295 95
296 96
297 97
298 98
299 99
300
301
302
303
304
305
306
307
308 8
309 9
310
311
312
313
314
315
316
317
318 8
319 9
320
321
322
323
324
325
326
327
328 8
329 9
330
331
332
333
334
335
336
337
338 8
339 9
340
341
342
343
344
345
346
347
348 8
349 9
350
351
352
353
354
355
356
357
358 8
359 9
360
361
362
363
364
365
366
367
368 8
369 9
370
371
372
373
374
375
376
377
378 8
379 9
380 80
381 81
382 82
383 83
384 84
385 85
386 86
387 87
388 88
389 89
390 90
391 91
392 92
393 93
394 94
395 95
396 96
397 97
398 98
399 99
400

keefaz 02-04-2005 03:15 PM

It should be more educative to post code than result of script

Something like:
Code:

#!/bin/bash

i=0
while [ $i -lt 400 ]; do
    printf "%i : %b\n" "$i" "\0$i"
    let "i++"
done



All times are GMT -5. The time now is 10:14 PM.