What are these three extra chars and why do they cause such a strange error? [duplicate]
This question already has an answer here:
#!/bin/bash - no such file or directory
8 answers
Look at these two files:
- File 1
- File 2
They look to me entirely identical, but File 1 has 41 bytes and File 2 has 44 bytes.
Now, I would not care about 3 extra chars, however, I think these chars are also responsible to a strange error: when I clone and run these files, File 1 runs OK while File 2 returns an error on line 3: "./BasicCheck.sh: line 3: cd: case0 : No such file or directory".
So: what are these extra chars? Why do they cause errors? And what should I do to fix these errors?
My guess is that they are newlines - perhaps File 1 has Linux-based newlines and File 2 has Windows-based newlines. Is it correct? And why should it cause such errors?
bash error-handling
marked as duplicate by glenn jackman, mosvy, Gilles
StackExchange.ready(function() {
if (StackExchange.options.isMobile) return;
$('.dupe-hammer-message-hover:not(.hover-bound)').each(function() {
var $hover = $(this).addClass('hover-bound'),
$msg = $hover.siblings('.dupe-hammer-message');
$hover.hover(
function() {
$hover.showInfoMessage('', {
messageElement: $msg.clone().show(),
transient: false,
position: { my: 'bottom left', at: 'top center', offsetTop: -7 },
dismissable: false,
relativeToBody: true
});
},
function() {
StackExchange.helpers.removeMessages();
}
);
});
});
yesterday
This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.
|
show 4 more comments
This question already has an answer here:
#!/bin/bash - no such file or directory
8 answers
Look at these two files:
- File 1
- File 2
They look to me entirely identical, but File 1 has 41 bytes and File 2 has 44 bytes.
Now, I would not care about 3 extra chars, however, I think these chars are also responsible to a strange error: when I clone and run these files, File 1 runs OK while File 2 returns an error on line 3: "./BasicCheck.sh: line 3: cd: case0 : No such file or directory".
So: what are these extra chars? Why do they cause errors? And what should I do to fix these errors?
My guess is that they are newlines - perhaps File 1 has Linux-based newlines and File 2 has Windows-based newlines. Is it correct? And why should it cause such errors?
bash error-handling
marked as duplicate by glenn jackman, mosvy, Gilles
StackExchange.ready(function() {
if (StackExchange.options.isMobile) return;
$('.dupe-hammer-message-hover:not(.hover-bound)').each(function() {
var $hover = $(this).addClass('hover-bound'),
$msg = $hover.siblings('.dupe-hammer-message');
$hover.hover(
function() {
$hover.showInfoMessage('', {
messageElement: $msg.clone().show(),
transient: false,
position: { my: 'bottom left', at: 'top center', offsetTop: -7 },
dismissable: false,
relativeToBody: true
});
},
function() {
StackExchange.helpers.removeMessages();
}
);
});
});
yesterday
This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.
8
Don't make us chase links. Post the text here, and highlight the differences.
– glenn jackman
yesterday
2
@glennjackman that's exactly the point - there are no visible differences. If I copy the text from both links, they will appear exactly the same and there will be no way to find out the difference. This is why I give the links to the original files.
– Erel Segal-Halevi
yesterday
6
Run both scripts throughod -c filename
and you'll be shown the exact characters in the files. If one script has DOS-style newlines (with a 3 line file, that would account for the extra 3 bytes) then I would have expected a different error message. Or specifically, the same error message, but "garbled".
– glenn jackman
yesterday
2
Please also show exactly how you invoke these scripts.
– glenn jackman
yesterday
1
One file has lines terminated by cr/lf (dos mode), the other just by lf (unix mode). The extra chars are carriage returns / r / CR / ascii 13.
– mosvy
yesterday
|
show 4 more comments
This question already has an answer here:
#!/bin/bash - no such file or directory
8 answers
Look at these two files:
- File 1
- File 2
They look to me entirely identical, but File 1 has 41 bytes and File 2 has 44 bytes.
Now, I would not care about 3 extra chars, however, I think these chars are also responsible to a strange error: when I clone and run these files, File 1 runs OK while File 2 returns an error on line 3: "./BasicCheck.sh: line 3: cd: case0 : No such file or directory".
So: what are these extra chars? Why do they cause errors? And what should I do to fix these errors?
My guess is that they are newlines - perhaps File 1 has Linux-based newlines and File 2 has Windows-based newlines. Is it correct? And why should it cause such errors?
bash error-handling
This question already has an answer here:
#!/bin/bash - no such file or directory
8 answers
Look at these two files:
- File 1
- File 2
They look to me entirely identical, but File 1 has 41 bytes and File 2 has 44 bytes.
Now, I would not care about 3 extra chars, however, I think these chars are also responsible to a strange error: when I clone and run these files, File 1 runs OK while File 2 returns an error on line 3: "./BasicCheck.sh: line 3: cd: case0 : No such file or directory".
So: what are these extra chars? Why do they cause errors? And what should I do to fix these errors?
My guess is that they are newlines - perhaps File 1 has Linux-based newlines and File 2 has Windows-based newlines. Is it correct? And why should it cause such errors?
This question already has an answer here:
#!/bin/bash - no such file or directory
8 answers
bash error-handling
bash error-handling
asked yesterday
Erel Segal-HaleviErel Segal-Halevi
305128
305128
marked as duplicate by glenn jackman, mosvy, Gilles
StackExchange.ready(function() {
if (StackExchange.options.isMobile) return;
$('.dupe-hammer-message-hover:not(.hover-bound)').each(function() {
var $hover = $(this).addClass('hover-bound'),
$msg = $hover.siblings('.dupe-hammer-message');
$hover.hover(
function() {
$hover.showInfoMessage('', {
messageElement: $msg.clone().show(),
transient: false,
position: { my: 'bottom left', at: 'top center', offsetTop: -7 },
dismissable: false,
relativeToBody: true
});
},
function() {
StackExchange.helpers.removeMessages();
}
);
});
});
yesterday
This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.
marked as duplicate by glenn jackman, mosvy, Gilles
StackExchange.ready(function() {
if (StackExchange.options.isMobile) return;
$('.dupe-hammer-message-hover:not(.hover-bound)').each(function() {
var $hover = $(this).addClass('hover-bound'),
$msg = $hover.siblings('.dupe-hammer-message');
$hover.hover(
function() {
$hover.showInfoMessage('', {
messageElement: $msg.clone().show(),
transient: false,
position: { my: 'bottom left', at: 'top center', offsetTop: -7 },
dismissable: false,
relativeToBody: true
});
},
function() {
StackExchange.helpers.removeMessages();
}
);
});
});
yesterday
This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.
8
Don't make us chase links. Post the text here, and highlight the differences.
– glenn jackman
yesterday
2
@glennjackman that's exactly the point - there are no visible differences. If I copy the text from both links, they will appear exactly the same and there will be no way to find out the difference. This is why I give the links to the original files.
– Erel Segal-Halevi
yesterday
6
Run both scripts throughod -c filename
and you'll be shown the exact characters in the files. If one script has DOS-style newlines (with a 3 line file, that would account for the extra 3 bytes) then I would have expected a different error message. Or specifically, the same error message, but "garbled".
– glenn jackman
yesterday
2
Please also show exactly how you invoke these scripts.
– glenn jackman
yesterday
1
One file has lines terminated by cr/lf (dos mode), the other just by lf (unix mode). The extra chars are carriage returns / r / CR / ascii 13.
– mosvy
yesterday
|
show 4 more comments
8
Don't make us chase links. Post the text here, and highlight the differences.
– glenn jackman
yesterday
2
@glennjackman that's exactly the point - there are no visible differences. If I copy the text from both links, they will appear exactly the same and there will be no way to find out the difference. This is why I give the links to the original files.
– Erel Segal-Halevi
yesterday
6
Run both scripts throughod -c filename
and you'll be shown the exact characters in the files. If one script has DOS-style newlines (with a 3 line file, that would account for the extra 3 bytes) then I would have expected a different error message. Or specifically, the same error message, but "garbled".
– glenn jackman
yesterday
2
Please also show exactly how you invoke these scripts.
– glenn jackman
yesterday
1
One file has lines terminated by cr/lf (dos mode), the other just by lf (unix mode). The extra chars are carriage returns / r / CR / ascii 13.
– mosvy
yesterday
8
8
Don't make us chase links. Post the text here, and highlight the differences.
– glenn jackman
yesterday
Don't make us chase links. Post the text here, and highlight the differences.
– glenn jackman
yesterday
2
2
@glennjackman that's exactly the point - there are no visible differences. If I copy the text from both links, they will appear exactly the same and there will be no way to find out the difference. This is why I give the links to the original files.
– Erel Segal-Halevi
yesterday
@glennjackman that's exactly the point - there are no visible differences. If I copy the text from both links, they will appear exactly the same and there will be no way to find out the difference. This is why I give the links to the original files.
– Erel Segal-Halevi
yesterday
6
6
Run both scripts through
od -c filename
and you'll be shown the exact characters in the files. If one script has DOS-style newlines (with a 3 line file, that would account for the extra 3 bytes) then I would have expected a different error message. Or specifically, the same error message, but "garbled".– glenn jackman
yesterday
Run both scripts through
od -c filename
and you'll be shown the exact characters in the files. If one script has DOS-style newlines (with a 3 line file, that would account for the extra 3 bytes) then I would have expected a different error message. Or specifically, the same error message, but "garbled".– glenn jackman
yesterday
2
2
Please also show exactly how you invoke these scripts.
– glenn jackman
yesterday
Please also show exactly how you invoke these scripts.
– glenn jackman
yesterday
1
1
One file has lines terminated by cr/lf (dos mode), the other just by lf (unix mode). The extra chars are carriage returns / r / CR / ascii 13.
– mosvy
yesterday
One file has lines terminated by cr/lf (dos mode), the other just by lf (unix mode). The extra chars are carriage returns / r / CR / ascii 13.
– mosvy
yesterday
|
show 4 more comments
1 Answer
1
active
oldest
votes
The file
command points out the issue:
% file file*
file1: Bourne-Again shell script, ASCII text executable
file2: Bourne-Again shell script, ASCII text executable, with CRLF line terminators
The second script is in "DOS" format. and so will not work as expected. You can convert it with dos2unix
and the results are now the same
% dos2unix file2
dos2unix: converting file file2 to Unix format ...
% ls -l file1 file2
-rw-r--r-- 1 sweh sweh 41 Mar 19 11:23 file1
-rw-r--r-- 1 sweh sweh 41 Mar 19 11:25 file2
When you try to use a DOS format file with Unix commands, there is a trailing control-M at the end of every line. So a line such as
a=b
will really set a
to b followed by control-M, shorthand ^M
:
a=b^M
Every command will be similarly impacted; eg a simple line with the two-character command ls
would try to run the three-character command ls<control-M>
, which doesn't exist.
add a comment |
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
The file
command points out the issue:
% file file*
file1: Bourne-Again shell script, ASCII text executable
file2: Bourne-Again shell script, ASCII text executable, with CRLF line terminators
The second script is in "DOS" format. and so will not work as expected. You can convert it with dos2unix
and the results are now the same
% dos2unix file2
dos2unix: converting file file2 to Unix format ...
% ls -l file1 file2
-rw-r--r-- 1 sweh sweh 41 Mar 19 11:23 file1
-rw-r--r-- 1 sweh sweh 41 Mar 19 11:25 file2
When you try to use a DOS format file with Unix commands, there is a trailing control-M at the end of every line. So a line such as
a=b
will really set a
to b followed by control-M, shorthand ^M
:
a=b^M
Every command will be similarly impacted; eg a simple line with the two-character command ls
would try to run the three-character command ls<control-M>
, which doesn't exist.
add a comment |
The file
command points out the issue:
% file file*
file1: Bourne-Again shell script, ASCII text executable
file2: Bourne-Again shell script, ASCII text executable, with CRLF line terminators
The second script is in "DOS" format. and so will not work as expected. You can convert it with dos2unix
and the results are now the same
% dos2unix file2
dos2unix: converting file file2 to Unix format ...
% ls -l file1 file2
-rw-r--r-- 1 sweh sweh 41 Mar 19 11:23 file1
-rw-r--r-- 1 sweh sweh 41 Mar 19 11:25 file2
When you try to use a DOS format file with Unix commands, there is a trailing control-M at the end of every line. So a line such as
a=b
will really set a
to b followed by control-M, shorthand ^M
:
a=b^M
Every command will be similarly impacted; eg a simple line with the two-character command ls
would try to run the three-character command ls<control-M>
, which doesn't exist.
add a comment |
The file
command points out the issue:
% file file*
file1: Bourne-Again shell script, ASCII text executable
file2: Bourne-Again shell script, ASCII text executable, with CRLF line terminators
The second script is in "DOS" format. and so will not work as expected. You can convert it with dos2unix
and the results are now the same
% dos2unix file2
dos2unix: converting file file2 to Unix format ...
% ls -l file1 file2
-rw-r--r-- 1 sweh sweh 41 Mar 19 11:23 file1
-rw-r--r-- 1 sweh sweh 41 Mar 19 11:25 file2
When you try to use a DOS format file with Unix commands, there is a trailing control-M at the end of every line. So a line such as
a=b
will really set a
to b followed by control-M, shorthand ^M
:
a=b^M
Every command will be similarly impacted; eg a simple line with the two-character command ls
would try to run the three-character command ls<control-M>
, which doesn't exist.
The file
command points out the issue:
% file file*
file1: Bourne-Again shell script, ASCII text executable
file2: Bourne-Again shell script, ASCII text executable, with CRLF line terminators
The second script is in "DOS" format. and so will not work as expected. You can convert it with dos2unix
and the results are now the same
% dos2unix file2
dos2unix: converting file file2 to Unix format ...
% ls -l file1 file2
-rw-r--r-- 1 sweh sweh 41 Mar 19 11:23 file1
-rw-r--r-- 1 sweh sweh 41 Mar 19 11:25 file2
When you try to use a DOS format file with Unix commands, there is a trailing control-M at the end of every line. So a line such as
a=b
will really set a
to b followed by control-M, shorthand ^M
:
a=b^M
Every command will be similarly impacted; eg a simple line with the two-character command ls
would try to run the three-character command ls<control-M>
, which doesn't exist.
edited yesterday
Rich
367212
367212
answered yesterday
Stephen HarrisStephen Harris
26.7k35181
26.7k35181
add a comment |
add a comment |
8
Don't make us chase links. Post the text here, and highlight the differences.
– glenn jackman
yesterday
2
@glennjackman that's exactly the point - there are no visible differences. If I copy the text from both links, they will appear exactly the same and there will be no way to find out the difference. This is why I give the links to the original files.
– Erel Segal-Halevi
yesterday
6
Run both scripts through
od -c filename
and you'll be shown the exact characters in the files. If one script has DOS-style newlines (with a 3 line file, that would account for the extra 3 bytes) then I would have expected a different error message. Or specifically, the same error message, but "garbled".– glenn jackman
yesterday
2
Please also show exactly how you invoke these scripts.
– glenn jackman
yesterday
1
One file has lines terminated by cr/lf (dos mode), the other just by lf (unix mode). The extra chars are carriage returns / r / CR / ascii 13.
– mosvy
yesterday