sed - No such file or directory
up vote
-1
down vote
favorite
So, I'm aware of that this topic has been discussed in several ways, but the responses didn't work for me.
I'm using sed to remove a line from a script, but each time I execute the bash script, I receive an error message "No such file or directory". I'm able run the command from the remote host terminal. See the sed command below.
#!/bin/bash
declare server_list="/location/of/iplist.txt"
declare file="/location/of/file/to/modify"
declare regex='"/export JAVA_HOME=/jvm/home/directory/java/d"'
declare file_content="$(sudo grep -Fxq export
JAVA_HOME=/java/home/directory/java "${file}" )
declare script="sudo sed -i -e ${regex} ${file}"
date
cat ${server_list} | while read server
do
# connect to each server and execute the "sed -i" command
ssh -I /location/of/pub/key ${server} -o StrictHostKeyChecking=no
# read file content into condition statement
${file_content}
if [ $? -eq 0 ];
then
# confirm string exist and remove the line
echo "JAVA_HOME located on ${server}"
"${script}"
else
echo "No JAVA_HOME located on ${server}"
fi
done
linux bash centos
|
show 3 more comments
up vote
-1
down vote
favorite
So, I'm aware of that this topic has been discussed in several ways, but the responses didn't work for me.
I'm using sed to remove a line from a script, but each time I execute the bash script, I receive an error message "No such file or directory". I'm able run the command from the remote host terminal. See the sed command below.
#!/bin/bash
declare server_list="/location/of/iplist.txt"
declare file="/location/of/file/to/modify"
declare regex='"/export JAVA_HOME=/jvm/home/directory/java/d"'
declare file_content="$(sudo grep -Fxq export
JAVA_HOME=/java/home/directory/java "${file}" )
declare script="sudo sed -i -e ${regex} ${file}"
date
cat ${server_list} | while read server
do
# connect to each server and execute the "sed -i" command
ssh -I /location/of/pub/key ${server} -o StrictHostKeyChecking=no
# read file content into condition statement
${file_content}
if [ $? -eq 0 ];
then
# confirm string exist and remove the line
echo "JAVA_HOME located on ${server}"
"${script}"
else
echo "No JAVA_HOME located on ${server}"
fi
done
linux bash centos
put your file, where you are trying to change
– Incrivel Monstro Verde
Nov 20 at 14:46
1
You might do well to put a -e after the -i. The -i parameter can take an option - the suffix to add to the backup file. In the case above, you may be telling sed that the file you want to modify is called "/export JAVA_HOME=/usr/lib/jvm/java/d", which of course it can't find. One more suggestion is to put your sed commands into a file and the use the sed -f <file> <input> > <output> first, before playing with the -i option.
– Mark
Nov 20 at 14:50
Your script has an entire command line quoted somewhere, as if you had typed'sudo sed -i "/export JAVA_HOME=/usr/lib/jvm/java/d"'
at the prompt instead ofsudo sed -i "/export JAVA_HOME=/usr/lib/jvm/java/d"
.
– chepner
Nov 20 at 14:54
@chepner Thank you for your response. I modified the script, but the error still exist. "No such file or directory"
– user3593238
Nov 20 at 16:19
1
@user3593238 You are quoting$script
. See I'm trying to put a command in a variable, but the complex cases always fail!.
– chepner
Nov 20 at 16:55
|
show 3 more comments
up vote
-1
down vote
favorite
up vote
-1
down vote
favorite
So, I'm aware of that this topic has been discussed in several ways, but the responses didn't work for me.
I'm using sed to remove a line from a script, but each time I execute the bash script, I receive an error message "No such file or directory". I'm able run the command from the remote host terminal. See the sed command below.
#!/bin/bash
declare server_list="/location/of/iplist.txt"
declare file="/location/of/file/to/modify"
declare regex='"/export JAVA_HOME=/jvm/home/directory/java/d"'
declare file_content="$(sudo grep -Fxq export
JAVA_HOME=/java/home/directory/java "${file}" )
declare script="sudo sed -i -e ${regex} ${file}"
date
cat ${server_list} | while read server
do
# connect to each server and execute the "sed -i" command
ssh -I /location/of/pub/key ${server} -o StrictHostKeyChecking=no
# read file content into condition statement
${file_content}
if [ $? -eq 0 ];
then
# confirm string exist and remove the line
echo "JAVA_HOME located on ${server}"
"${script}"
else
echo "No JAVA_HOME located on ${server}"
fi
done
linux bash centos
So, I'm aware of that this topic has been discussed in several ways, but the responses didn't work for me.
I'm using sed to remove a line from a script, but each time I execute the bash script, I receive an error message "No such file or directory". I'm able run the command from the remote host terminal. See the sed command below.
#!/bin/bash
declare server_list="/location/of/iplist.txt"
declare file="/location/of/file/to/modify"
declare regex='"/export JAVA_HOME=/jvm/home/directory/java/d"'
declare file_content="$(sudo grep -Fxq export
JAVA_HOME=/java/home/directory/java "${file}" )
declare script="sudo sed -i -e ${regex} ${file}"
date
cat ${server_list} | while read server
do
# connect to each server and execute the "sed -i" command
ssh -I /location/of/pub/key ${server} -o StrictHostKeyChecking=no
# read file content into condition statement
${file_content}
if [ $? -eq 0 ];
then
# confirm string exist and remove the line
echo "JAVA_HOME located on ${server}"
"${script}"
else
echo "No JAVA_HOME located on ${server}"
fi
done
linux bash centos
linux bash centos
edited Nov 20 at 16:14
asked Nov 20 at 14:42
user3593238
11
11
put your file, where you are trying to change
– Incrivel Monstro Verde
Nov 20 at 14:46
1
You might do well to put a -e after the -i. The -i parameter can take an option - the suffix to add to the backup file. In the case above, you may be telling sed that the file you want to modify is called "/export JAVA_HOME=/usr/lib/jvm/java/d", which of course it can't find. One more suggestion is to put your sed commands into a file and the use the sed -f <file> <input> > <output> first, before playing with the -i option.
– Mark
Nov 20 at 14:50
Your script has an entire command line quoted somewhere, as if you had typed'sudo sed -i "/export JAVA_HOME=/usr/lib/jvm/java/d"'
at the prompt instead ofsudo sed -i "/export JAVA_HOME=/usr/lib/jvm/java/d"
.
– chepner
Nov 20 at 14:54
@chepner Thank you for your response. I modified the script, but the error still exist. "No such file or directory"
– user3593238
Nov 20 at 16:19
1
@user3593238 You are quoting$script
. See I'm trying to put a command in a variable, but the complex cases always fail!.
– chepner
Nov 20 at 16:55
|
show 3 more comments
put your file, where you are trying to change
– Incrivel Monstro Verde
Nov 20 at 14:46
1
You might do well to put a -e after the -i. The -i parameter can take an option - the suffix to add to the backup file. In the case above, you may be telling sed that the file you want to modify is called "/export JAVA_HOME=/usr/lib/jvm/java/d", which of course it can't find. One more suggestion is to put your sed commands into a file and the use the sed -f <file> <input> > <output> first, before playing with the -i option.
– Mark
Nov 20 at 14:50
Your script has an entire command line quoted somewhere, as if you had typed'sudo sed -i "/export JAVA_HOME=/usr/lib/jvm/java/d"'
at the prompt instead ofsudo sed -i "/export JAVA_HOME=/usr/lib/jvm/java/d"
.
– chepner
Nov 20 at 14:54
@chepner Thank you for your response. I modified the script, but the error still exist. "No such file or directory"
– user3593238
Nov 20 at 16:19
1
@user3593238 You are quoting$script
. See I'm trying to put a command in a variable, but the complex cases always fail!.
– chepner
Nov 20 at 16:55
put your file, where you are trying to change
– Incrivel Monstro Verde
Nov 20 at 14:46
put your file, where you are trying to change
– Incrivel Monstro Verde
Nov 20 at 14:46
1
1
You might do well to put a -e after the -i. The -i parameter can take an option - the suffix to add to the backup file. In the case above, you may be telling sed that the file you want to modify is called "/export JAVA_HOME=/usr/lib/jvm/java/d", which of course it can't find. One more suggestion is to put your sed commands into a file and the use the sed -f <file> <input> > <output> first, before playing with the -i option.
– Mark
Nov 20 at 14:50
You might do well to put a -e after the -i. The -i parameter can take an option - the suffix to add to the backup file. In the case above, you may be telling sed that the file you want to modify is called "/export JAVA_HOME=/usr/lib/jvm/java/d", which of course it can't find. One more suggestion is to put your sed commands into a file and the use the sed -f <file> <input> > <output> first, before playing with the -i option.
– Mark
Nov 20 at 14:50
Your script has an entire command line quoted somewhere, as if you had typed
'sudo sed -i "/export JAVA_HOME=/usr/lib/jvm/java/d"'
at the prompt instead of sudo sed -i "/export JAVA_HOME=/usr/lib/jvm/java/d"
.– chepner
Nov 20 at 14:54
Your script has an entire command line quoted somewhere, as if you had typed
'sudo sed -i "/export JAVA_HOME=/usr/lib/jvm/java/d"'
at the prompt instead of sudo sed -i "/export JAVA_HOME=/usr/lib/jvm/java/d"
.– chepner
Nov 20 at 14:54
@chepner Thank you for your response. I modified the script, but the error still exist. "No such file or directory"
– user3593238
Nov 20 at 16:19
@chepner Thank you for your response. I modified the script, but the error still exist. "No such file or directory"
– user3593238
Nov 20 at 16:19
1
1
@user3593238 You are quoting
$script
. See I'm trying to put a command in a variable, but the complex cases always fail!.– chepner
Nov 20 at 16:55
@user3593238 You are quoting
$script
. See I'm trying to put a command in a variable, but the complex cases always fail!.– chepner
Nov 20 at 16:55
|
show 3 more comments
2 Answers
2
active
oldest
votes
up vote
0
down vote
Don't put complete commands in variables. "${script}"
is an invitation for trouble.
An illustrative example:
me ~ > echo -e 'foo barnbaz qux' > /tmp/foobar
me ~ > cat /tmp/foobar
foo bar
baz qux
me ~ > sed -e '/foo bar/d' /tmp/foobar
baz qux
me ~ > cmd="sed -e '/foo bar/d' /tmp/foobar"
me ~ > $cmd
sed: -e expression #1, char 1: unknown command: `''
me ~ > ${cmd}
sed: -e expression #1, char 1: unknown command: `''
me ~ > "$cmd"
bash: sed -e '/foo bar/d' /tmp/foobar: No such file or directory
me ~ > "${cmd}"
bash: sed -e '/foo bar/d' /tmp/foobar: No such file or directory
What's going on here? If you use $cmd
unquoted, sed
has following 4 arguments:
-e
'/foo
bar/d'
/tmp/foobar
(yes that's how "words" in bash work). Obviously sed
cannot interpret this gibberish.
If you try running "$cmd"
or "${cmd}"
, the entire string is interpreted as the command name, spaces quotes and all. The shell complains it cannot find an executable file named sed -e '/foo bar/d' /tmp/foobar
, and it's absolutely right. No good either.
Solution?
A quick and dirty hack is
me ~ > eval ${cmd}
baz qux
Works as expected! However, eval is dangerous and should not be used unless you are a certified shell guru. (Which you, I believe, still are not). A better option is to define a function.
cmd() {
sed -e '/foo bar/d' /tmp/foobar
}
...
cmd
add a comment |
up vote
0
down vote
Try to use eval to execute variable content
declare file="/location/of/file/to/modify"
declare regex='"/export JAVA_HOME=/jvm/home/directory/java/d"'
declare script="sudo sed -i -e ${regex} ${file}"
eval ${script}
Okay. When I execute the script it returns this error:regex='"/export JAVA_HOME=/jvm/home/directory/java/d"'
sed: 1: "JAVA_HOME=/usr/lib/jvm/ ...": invalid command code J
When I removed the regular expressions, I get this:regex='"/export JAVA_HOME=jvmhomedirectory/java/d"'
sed: 1: "/export": unterminated regular expression `
– user3593238
Nov 21 at 16:25
add a comment |
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53395460%2fsed-no-such-file-or-directory%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
0
down vote
Don't put complete commands in variables. "${script}"
is an invitation for trouble.
An illustrative example:
me ~ > echo -e 'foo barnbaz qux' > /tmp/foobar
me ~ > cat /tmp/foobar
foo bar
baz qux
me ~ > sed -e '/foo bar/d' /tmp/foobar
baz qux
me ~ > cmd="sed -e '/foo bar/d' /tmp/foobar"
me ~ > $cmd
sed: -e expression #1, char 1: unknown command: `''
me ~ > ${cmd}
sed: -e expression #1, char 1: unknown command: `''
me ~ > "$cmd"
bash: sed -e '/foo bar/d' /tmp/foobar: No such file or directory
me ~ > "${cmd}"
bash: sed -e '/foo bar/d' /tmp/foobar: No such file or directory
What's going on here? If you use $cmd
unquoted, sed
has following 4 arguments:
-e
'/foo
bar/d'
/tmp/foobar
(yes that's how "words" in bash work). Obviously sed
cannot interpret this gibberish.
If you try running "$cmd"
or "${cmd}"
, the entire string is interpreted as the command name, spaces quotes and all. The shell complains it cannot find an executable file named sed -e '/foo bar/d' /tmp/foobar
, and it's absolutely right. No good either.
Solution?
A quick and dirty hack is
me ~ > eval ${cmd}
baz qux
Works as expected! However, eval is dangerous and should not be used unless you are a certified shell guru. (Which you, I believe, still are not). A better option is to define a function.
cmd() {
sed -e '/foo bar/d' /tmp/foobar
}
...
cmd
add a comment |
up vote
0
down vote
Don't put complete commands in variables. "${script}"
is an invitation for trouble.
An illustrative example:
me ~ > echo -e 'foo barnbaz qux' > /tmp/foobar
me ~ > cat /tmp/foobar
foo bar
baz qux
me ~ > sed -e '/foo bar/d' /tmp/foobar
baz qux
me ~ > cmd="sed -e '/foo bar/d' /tmp/foobar"
me ~ > $cmd
sed: -e expression #1, char 1: unknown command: `''
me ~ > ${cmd}
sed: -e expression #1, char 1: unknown command: `''
me ~ > "$cmd"
bash: sed -e '/foo bar/d' /tmp/foobar: No such file or directory
me ~ > "${cmd}"
bash: sed -e '/foo bar/d' /tmp/foobar: No such file or directory
What's going on here? If you use $cmd
unquoted, sed
has following 4 arguments:
-e
'/foo
bar/d'
/tmp/foobar
(yes that's how "words" in bash work). Obviously sed
cannot interpret this gibberish.
If you try running "$cmd"
or "${cmd}"
, the entire string is interpreted as the command name, spaces quotes and all. The shell complains it cannot find an executable file named sed -e '/foo bar/d' /tmp/foobar
, and it's absolutely right. No good either.
Solution?
A quick and dirty hack is
me ~ > eval ${cmd}
baz qux
Works as expected! However, eval is dangerous and should not be used unless you are a certified shell guru. (Which you, I believe, still are not). A better option is to define a function.
cmd() {
sed -e '/foo bar/d' /tmp/foobar
}
...
cmd
add a comment |
up vote
0
down vote
up vote
0
down vote
Don't put complete commands in variables. "${script}"
is an invitation for trouble.
An illustrative example:
me ~ > echo -e 'foo barnbaz qux' > /tmp/foobar
me ~ > cat /tmp/foobar
foo bar
baz qux
me ~ > sed -e '/foo bar/d' /tmp/foobar
baz qux
me ~ > cmd="sed -e '/foo bar/d' /tmp/foobar"
me ~ > $cmd
sed: -e expression #1, char 1: unknown command: `''
me ~ > ${cmd}
sed: -e expression #1, char 1: unknown command: `''
me ~ > "$cmd"
bash: sed -e '/foo bar/d' /tmp/foobar: No such file or directory
me ~ > "${cmd}"
bash: sed -e '/foo bar/d' /tmp/foobar: No such file or directory
What's going on here? If you use $cmd
unquoted, sed
has following 4 arguments:
-e
'/foo
bar/d'
/tmp/foobar
(yes that's how "words" in bash work). Obviously sed
cannot interpret this gibberish.
If you try running "$cmd"
or "${cmd}"
, the entire string is interpreted as the command name, spaces quotes and all. The shell complains it cannot find an executable file named sed -e '/foo bar/d' /tmp/foobar
, and it's absolutely right. No good either.
Solution?
A quick and dirty hack is
me ~ > eval ${cmd}
baz qux
Works as expected! However, eval is dangerous and should not be used unless you are a certified shell guru. (Which you, I believe, still are not). A better option is to define a function.
cmd() {
sed -e '/foo bar/d' /tmp/foobar
}
...
cmd
Don't put complete commands in variables. "${script}"
is an invitation for trouble.
An illustrative example:
me ~ > echo -e 'foo barnbaz qux' > /tmp/foobar
me ~ > cat /tmp/foobar
foo bar
baz qux
me ~ > sed -e '/foo bar/d' /tmp/foobar
baz qux
me ~ > cmd="sed -e '/foo bar/d' /tmp/foobar"
me ~ > $cmd
sed: -e expression #1, char 1: unknown command: `''
me ~ > ${cmd}
sed: -e expression #1, char 1: unknown command: `''
me ~ > "$cmd"
bash: sed -e '/foo bar/d' /tmp/foobar: No such file or directory
me ~ > "${cmd}"
bash: sed -e '/foo bar/d' /tmp/foobar: No such file or directory
What's going on here? If you use $cmd
unquoted, sed
has following 4 arguments:
-e
'/foo
bar/d'
/tmp/foobar
(yes that's how "words" in bash work). Obviously sed
cannot interpret this gibberish.
If you try running "$cmd"
or "${cmd}"
, the entire string is interpreted as the command name, spaces quotes and all. The shell complains it cannot find an executable file named sed -e '/foo bar/d' /tmp/foobar
, and it's absolutely right. No good either.
Solution?
A quick and dirty hack is
me ~ > eval ${cmd}
baz qux
Works as expected! However, eval is dangerous and should not be used unless you are a certified shell guru. (Which you, I believe, still are not). A better option is to define a function.
cmd() {
sed -e '/foo bar/d' /tmp/foobar
}
...
cmd
answered Nov 20 at 17:08
n.m.
70.9k882166
70.9k882166
add a comment |
add a comment |
up vote
0
down vote
Try to use eval to execute variable content
declare file="/location/of/file/to/modify"
declare regex='"/export JAVA_HOME=/jvm/home/directory/java/d"'
declare script="sudo sed -i -e ${regex} ${file}"
eval ${script}
Okay. When I execute the script it returns this error:regex='"/export JAVA_HOME=/jvm/home/directory/java/d"'
sed: 1: "JAVA_HOME=/usr/lib/jvm/ ...": invalid command code J
When I removed the regular expressions, I get this:regex='"/export JAVA_HOME=jvmhomedirectory/java/d"'
sed: 1: "/export": unterminated regular expression `
– user3593238
Nov 21 at 16:25
add a comment |
up vote
0
down vote
Try to use eval to execute variable content
declare file="/location/of/file/to/modify"
declare regex='"/export JAVA_HOME=/jvm/home/directory/java/d"'
declare script="sudo sed -i -e ${regex} ${file}"
eval ${script}
Okay. When I execute the script it returns this error:regex='"/export JAVA_HOME=/jvm/home/directory/java/d"'
sed: 1: "JAVA_HOME=/usr/lib/jvm/ ...": invalid command code J
When I removed the regular expressions, I get this:regex='"/export JAVA_HOME=jvmhomedirectory/java/d"'
sed: 1: "/export": unterminated regular expression `
– user3593238
Nov 21 at 16:25
add a comment |
up vote
0
down vote
up vote
0
down vote
Try to use eval to execute variable content
declare file="/location/of/file/to/modify"
declare regex='"/export JAVA_HOME=/jvm/home/directory/java/d"'
declare script="sudo sed -i -e ${regex} ${file}"
eval ${script}
Try to use eval to execute variable content
declare file="/location/of/file/to/modify"
declare regex='"/export JAVA_HOME=/jvm/home/directory/java/d"'
declare script="sudo sed -i -e ${regex} ${file}"
eval ${script}
answered Nov 20 at 21:35
Marcos Arroyo Esteban
212
212
Okay. When I execute the script it returns this error:regex='"/export JAVA_HOME=/jvm/home/directory/java/d"'
sed: 1: "JAVA_HOME=/usr/lib/jvm/ ...": invalid command code J
When I removed the regular expressions, I get this:regex='"/export JAVA_HOME=jvmhomedirectory/java/d"'
sed: 1: "/export": unterminated regular expression `
– user3593238
Nov 21 at 16:25
add a comment |
Okay. When I execute the script it returns this error:regex='"/export JAVA_HOME=/jvm/home/directory/java/d"'
sed: 1: "JAVA_HOME=/usr/lib/jvm/ ...": invalid command code J
When I removed the regular expressions, I get this:regex='"/export JAVA_HOME=jvmhomedirectory/java/d"'
sed: 1: "/export": unterminated regular expression `
– user3593238
Nov 21 at 16:25
Okay. When I execute the script it returns this error:
regex='"/export JAVA_HOME=/jvm/home/directory/java/d"'
sed: 1: "JAVA_HOME=/usr/lib/jvm/ ...": invalid command code J
When I removed the regular expressions, I get this: regex='"/export JAVA_HOME=jvmhomedirectory/java/d"'
sed: 1: "/export": unterminated regular expression `– user3593238
Nov 21 at 16:25
Okay. When I execute the script it returns this error:
regex='"/export JAVA_HOME=/jvm/home/directory/java/d"'
sed: 1: "JAVA_HOME=/usr/lib/jvm/ ...": invalid command code J
When I removed the regular expressions, I get this: regex='"/export JAVA_HOME=jvmhomedirectory/java/d"'
sed: 1: "/export": unterminated regular expression `– user3593238
Nov 21 at 16:25
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Some of your past answers have not been well-received, and you're in danger of being blocked from answering.
Please pay close attention to the following guidance:
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53395460%2fsed-no-such-file-or-directory%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
put your file, where you are trying to change
– Incrivel Monstro Verde
Nov 20 at 14:46
1
You might do well to put a -e after the -i. The -i parameter can take an option - the suffix to add to the backup file. In the case above, you may be telling sed that the file you want to modify is called "/export JAVA_HOME=/usr/lib/jvm/java/d", which of course it can't find. One more suggestion is to put your sed commands into a file and the use the sed -f <file> <input> > <output> first, before playing with the -i option.
– Mark
Nov 20 at 14:50
Your script has an entire command line quoted somewhere, as if you had typed
'sudo sed -i "/export JAVA_HOME=/usr/lib/jvm/java/d"'
at the prompt instead ofsudo sed -i "/export JAVA_HOME=/usr/lib/jvm/java/d"
.– chepner
Nov 20 at 14:54
@chepner Thank you for your response. I modified the script, but the error still exist. "No such file or directory"
– user3593238
Nov 20 at 16:19
1
@user3593238 You are quoting
$script
. See I'm trying to put a command in a variable, but the complex cases always fail!.– chepner
Nov 20 at 16:55