Sponsored Content
Top Forums UNIX for Advanced & Expert Users Another binary manipulation thread. Post 302851081 by DGPickett on Friday 6th of September 2013 05:05:08 PM
Old 09-06-2013
Wel, in a null terminated string application, null is always '' the empty string, as it reterminates the string, just as a strcpy of a 5 byte plus null string into a 20 byte buffer initialized with 19 spaces and a null creates a string length of 5.

Now, is it the only character that is equal to '' the empty string? Does read differentiate that from EOF in a while read loop?
Code:
$ bash -c 'export ct=0 ; unset IFS ; all256|while read -rn 1 c
do
 echo "$(( ct++ )): '"'"'$c'"'"'"
done|cat -vt'
0: ''
1: '^A'
2: '^B'
3: '^C'
4: '^D'
5: '^E'
6: '^F'
7: '^G'
8: '^H'
9: ''
10: ''
11: '^K'
12: '^L'
13: '^M'
14: '^N'
15: '^O'
16: '^P'
17: '^Q'
18: '^R'
19: '^S'
20: '^T'
21: '^U'
22: '^V'
23: '^W'
24: '^X'
25: '^Y'
26: '^Z'
27: '^['
28: '^\'
29: '^]'
30: '^^'
31: '^_'
32: ''
33: '!'
34: '"'
35: '#'
36: '$'
37: '%'
38: '&'
39: '''
40: '('
41: ')'
42: '*'
43: '+'
44: ','
45: '-'
46: '.'
47: '/'
48: '0'
49: '1'
50: '2'
51: '3'
52: '4'
53: '5'
54: '6'
55: '7'
56: '8'
57: '9'
58: ':'
59: ';'
60: '<'
61: '='
62: '>'
63: '?'
64: '@'
65: 'A'
66: 'B'
67: 'C'
68: 'D'
69: 'E'
70: 'F'
71: 'G'
72: 'H'
73: 'I'
74: 'J'
75: 'K'
76: 'L'
77: 'M'
78: 'N'
79: 'O'
80: 'P'
81: 'Q'
82: 'R'
83: 'S'
84: 'T'
85: 'U'
86: 'V'
87: 'W'
88: 'X'
89: 'Y'
90: 'Z'
91: '['
92: '\'
93: ']'
94: '^'
95: '_'
96: '`'
97: 'a'
98: 'b'
99: 'c'
100: 'd'
101: 'e'
102: 'f'
103: 'g'
104: 'h'
105: 'i'
106: 'j'
107: 'k'
108: 'l'
109: 'm'
110: 'n'
111: 'o'
112: 'p'
113: 'q'
114: 'r'
115: 's'
116: 't'
117: 'u'
118: 'v'
119: 'w'
120: 'x'
121: 'y'
122: 'z'
123: '{'
124: '|'
125: '}'
126: '~'
127: '^?'
128: 'M-^@'
129: 'M-^A'
130: 'M-^B'
131: 'M-^C'
132: 'M-^D'
133: 'M-^E'
134: 'M-^F'
135: 'M-^G'
136: 'M-^H'
137: 'M-^I'
138: 'M-
'
139: 'M-^K'
140: 'M-^L'
141: 'M-^M'
142: 'M-^N'
143: 'M-^O'
144: 'M-^P'
145: 'M-^Q'
146: 'M-^R'
147: 'M-^S'
148: 'M-^T'
149: 'M-^U'
150: 'M-^V'
151: 'M-^W'
152: 'M-^X'
153: 'M-^Y'
154: 'M-^Z'
155: 'M-^['
156: 'M-^\'
157: 'M-^]'
158: 'M-^^'
159: 'M-^_'
160: 'M- '
161: 'M-!'
162: 'M-"'
163: 'M-#'
164: 'M-$'
165: 'M-%'
166: 'M-&'
167: 'M-''
168: 'M-('
169: 'M-)'
170: 'M-*'
171: 'M-+'
172: 'M-,'
173: 'M--'
174: 'M-.'
175: 'M-/'
176: 'M-0'
177: 'M-1'
178: 'M-2'
179: 'M-3'
180: 'M-4'
181: 'M-5'
182: 'M-6'
183: 'M-7'
184: 'M-8'
185: 'M-9'
186: 'M-:'
187: 'M-;'
188: 'M-<'
189: 'M-='
190: 'M->'
191: 'M-?'
192: 'M-@'
193: 'M-A'
194: 'M-B'
195: 'M-C'
196: 'M-D'
197: 'M-E'
198: 'M-F'
199: 'M-G'
200: 'M-H'
201: 'M-I'
202: 'M-J'
203: 'M-K'
204: 'M-L'
205: 'M-M'
206: 'M-N'
207: 'M-O'
208: 'M-P'
209: 'M-Q'
210: 'M-R'
211: 'M-S'
212: 'M-T'
213: 'M-U'
214: 'M-V'
215: 'M-W'
216: 'M-X'
217: 'M-Y'
218: 'M-Z'
219: 'M-['
220: 'M-\'
221: 'M-]'
222: 'M-^'
223: 'M-_'
224: 'M-`'
225: 'M-a'
226: 'M-b'
227: 'M-c'
228: 'M-d'
229: 'M-e'
230: 'M-f'
231: 'M-g'
232: 'M-h'
233: 'M-i'
234: 'M-j'
235: 'M-k'
236: 'M-l'
237: 'M-m'
238: 'M-n'
239: 'M-o'
240: 'M-p'
241: 'M-q'
242: 'M-r'
243: 'M-s'
244: 'M-t'
245: 'M-u'
246: 'M-v'
247: 'M-w'
248: 'M-x'
249: 'M-y'
250: 'M-z'
251: 'M-{'
252: 'M-|'
253: 'M-}'
254: 'M-~'
255: 'M-^?'
$

Too many aliases. Whatever is or defaults to IFS is indistinguishable from null:
Code:
$ bash -c 'export ct=0 IFS="
" ; all256|while read -ern 1 c
do
 echo "$(( ct++ )): '"'"'$c'"'"'"
done|cat -vt'
0: ''
1: '^A'
2: '^B'
3: '^C'
4: '^D'
5: '^E'
6: '^F'
7: '^G'
8: '^H'
9: '^I'
10: ''
11: '^K'
12: '^L'
13: '^M'
14: '^N'
15: '^O'
16: '^P'
17: '^Q'
18: '^R'
19: '^S'
20: '^T'
21: '^U'
22: '^V'
23: '^W'
24: '^X'
25: '^Y'
26: '^Z'
27: '^['
28: '^\'
29: '^]'
30: '^^'
31: '^_'
32: ' '
33: '!'
34: '"'
35: '#'
36: '$'
37: '%'
38: '&'
39: '''
40: '('
41: ')'
42: '*'
43: '+'
44: ','
45: '-'
46: '.'
47: '/'
48: '0'
49: '1'
50: '2'
51: '3'
52: '4'
53: '5'
54: '6'
55: '7'
56: '8'
57: '9'
58: ':'
59: ';'
60: '<'
61: '='
62: '>'
63: '?'
64: '@'
65: 'A'
66: 'B'
67: 'C'
68: 'D'
69: 'E'
70: 'F'
71: 'G'
72: 'H'
73: 'I'
74: 'J'
75: 'K'
76: 'L'
77: 'M'
78: 'N'
79: 'O'
80: 'P'
81: 'Q'
82: 'R'
83: 'S'
84: 'T'
85: 'U'
86: 'V'
87: 'W'
88: 'X'
89: 'Y'
90: 'Z'
91: '['
92: '\'
93: ']'
94: '^'
95: '_'
96: '`'
97: 'a'
98: 'b'
99: 'c'
100: 'd'
101: 'e'
102: 'f'
103: 'g'
104: 'h'
105: 'i'
106: 'j'
107: 'k'
108: 'l'
109: 'm'
110: 'n'
111: 'o'
112: 'p'
113: 'q'
114: 'r'
115: 's'
116: 't'
117: 'u'
118: 'v'
119: 'w'
120: 'x'
121: 'y'
122: 'z'
123: '{'
124: '|'
125: '}'
126: '~'
127: '^?'
128: 'M-^@'
129: 'M-^A'
130: 'M-^B'
131: 'M-^C'
132: 'M-^D'
133: 'M-^E'
134: 'M-^F'
135: 'M-^G'
136: 'M-^H'
137: 'M-^I'
138: 'M-
'
139: 'M-^K'
140: 'M-^L'
141: 'M-^M'
142: 'M-^N'
143: 'M-^O'
144: 'M-^P'
145: 'M-^Q'
146: 'M-^R'
147: 'M-^S'
148: 'M-^T'
149: 'M-^U'
150: 'M-^V'
151: 'M-^W'
152: 'M-^X'
153: 'M-^Y'
154: 'M-^Z'
155: 'M-^['
156: 'M-^\'
157: 'M-^]'
158: 'M-^^'
159: 'M-^_'
160: 'M- '
161: 'M-!'
162: 'M-"'
163: 'M-#'
164: 'M-$'
165: 'M-%'
166: 'M-&'
167: 'M-''
168: 'M-('
169: 'M-)'
170: 'M-*'
171: 'M-+'
172: 'M-,'
173: 'M--'
174: 'M-.'
175: 'M-/'
176: 'M-0'
177: 'M-1'
178: 'M-2'
179: 'M-3'
180: 'M-4'
181: 'M-5'
182: 'M-6'
183: 'M-7'
184: 'M-8'
185: 'M-9'
186: 'M-:'
187: 'M-;'
188: 'M-<'
189: 'M-='
190: 'M->'
191: 'M-?'
192: 'M-@'
193: 'M-A'
194: 'M-B'
195: 'M-C'
196: 'M-D'
197: 'M-E'
198: 'M-F'
199: 'M-G'
200: 'M-H'
201: 'M-I'
202: 'M-J'
203: 'M-K'
204: 'M-L'
205: 'M-M'
206: 'M-N'
207: 'M-O'
208: 'M-P'
209: 'M-Q'
210: 'M-R'
211: 'M-S'
212: 'M-T'
213: 'M-U'
214: 'M-V'
215: 'M-W'
216: 'M-X'
217: 'M-Y'
218: 'M-Z'
219: 'M-['
220: 'M-\'
221: 'M-]'
222: 'M-^'
223: 'M-_'
224: 'M-`'
225: 'M-a'
226: 'M-b'
227: 'M-c'
228: 'M-d'
229: 'M-e'
230: 'M-f'
231: 'M-g'
232: 'M-h'
233: 'M-i'
234: 'M-j'
235: 'M-k'
236: 'M-l'
237: 'M-m'
238: 'M-n'
239: 'M-o'
240: 'M-p'
241: 'M-q'
242: 'M-r'
243: 'M-s'
244: 'M-t'
245: 'M-u'
246: 'M-v'
247: 'M-w'
248: 'M-x'
249: 'M-y'
250: 'M-z'
251: 'M-{'
252: 'M-|'
253: 'M-}'
254: 'M-~'
255: 'M-^?'
$


Last edited by DGPickett; 09-06-2013 at 07:13 PM..
 

4 More Discussions You Might Find Interesting

1. Programming

How to cancel a thread safely from the initial thread?

how about asynchronous canceling? or with signal? if with signal whether it effects the process? my english so badly :( :( (1 Reply)
Discussion started by: alan.zhao
1 Replies

2. Shell Programming and Scripting

Convert binary file to csv and then back to the binary format

Hello *nix specialists, Im working for a non profit organisation in Germany to transport DSL over WLAN to people in areas without no DSL. We are using Linksys WRT 54 router with DD-WRT firmware There are at the moment over 180 router running but we have to change some settings next time. So my... (7 Replies)
Discussion started by: digidax
7 Replies

3. Shell Programming and Scripting

Another Building Block, Binary File Manipulation...

Apologies for any typos, and IF this has been done before... This is yet another building block. The code generates a 256 byte binary file of _characters_ 0x00 to 0xFF for general usage and generates another binary file manipulated in a basic way. I need this facility for a kids project I am... (0 Replies)
Discussion started by: wisecracker
0 Replies

4. Forum Support Area for Unregistered Users & Account Problems

Not able to post thread/reply to thread

Dear Moderator I am not able to post any new thread or post reply to mine old thread. Kindly help as i am stuck on one problem and needed suggestion. Regards Jaydeep (1 Reply)
Discussion started by: jaydeep_sadaria
1 Replies
All times are GMT -4. The time now is 05:13 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy