How to silence grep errors when used with a variable?
up vote
0
down vote
favorite
Note: I have a work around for this but feel that I shouldn't need it.
The following errors silently when typed into terminal
grep -oP "path:K(.+)/([^/]+)" ./tasks.txt -s
In a script file, the following will throw No such file or directory
pth=$(grep -oP "path:K(.+)/([^/]+)" ./tasks.txt -s)
grep: ./tasks.txt: No such file or directory
Why is the -s not working and how can the error be silenced?
Only just started when I ran into this error, here is my code so far.
#!/bin/bash
BINDIR=$(dirname "$(readlink -fn "$0")") # The curent directory path ie: /server/users/
SCR=$(basename -- "$0") # The name of this script ie: name.sh
SCRBASE=$(basename -- "$0" .sh) # The name of this script without extension ie: name
CWD=${BINDIR##*/} # The current directory name without the path ie: users
cd "$BINDIR"
pth="" # The path to the server root
name="" # The level name of the server
pth=$(grep -oP "path:K(.+)/([^/]+)" ./tasks.txt -s)
echo "path=$pth" > log.txt
shell-script error-handling
New contributor
Stuperfied is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
|
show 1 more comment
up vote
0
down vote
favorite
Note: I have a work around for this but feel that I shouldn't need it.
The following errors silently when typed into terminal
grep -oP "path:K(.+)/([^/]+)" ./tasks.txt -s
In a script file, the following will throw No such file or directory
pth=$(grep -oP "path:K(.+)/([^/]+)" ./tasks.txt -s)
grep: ./tasks.txt: No such file or directory
Why is the -s not working and how can the error be silenced?
Only just started when I ran into this error, here is my code so far.
#!/bin/bash
BINDIR=$(dirname "$(readlink -fn "$0")") # The curent directory path ie: /server/users/
SCR=$(basename -- "$0") # The name of this script ie: name.sh
SCRBASE=$(basename -- "$0" .sh) # The name of this script without extension ie: name
CWD=${BINDIR##*/} # The current directory name without the path ie: users
cd "$BINDIR"
pth="" # The path to the server root
name="" # The level name of the server
pth=$(grep -oP "path:K(.+)/([^/]+)" ./tasks.txt -s)
echo "path=$pth" > log.txt
shell-script error-handling
New contributor
Stuperfied is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
Are you sure the error message comes from that line?
– nohillside
1 hour ago
Does it work if you change the script tocdto a handcoded directory name and assigningpth(so that the script only contains the shebang and two lines of code)?
– nohillside
1 hour ago
@nohillside Nope. Also, the file does not actually exist. afaik the -s should be working but is not.
– Stuperfied
50 mins ago
I suspected one of the other lines to throw the error, actually :-) Can you add the full error message (the whole line) to make this clear?
– nohillside
42 mins ago
@nohillside Added the full error to the post.
– Stuperfied
37 mins ago
|
show 1 more comment
up vote
0
down vote
favorite
up vote
0
down vote
favorite
Note: I have a work around for this but feel that I shouldn't need it.
The following errors silently when typed into terminal
grep -oP "path:K(.+)/([^/]+)" ./tasks.txt -s
In a script file, the following will throw No such file or directory
pth=$(grep -oP "path:K(.+)/([^/]+)" ./tasks.txt -s)
grep: ./tasks.txt: No such file or directory
Why is the -s not working and how can the error be silenced?
Only just started when I ran into this error, here is my code so far.
#!/bin/bash
BINDIR=$(dirname "$(readlink -fn "$0")") # The curent directory path ie: /server/users/
SCR=$(basename -- "$0") # The name of this script ie: name.sh
SCRBASE=$(basename -- "$0" .sh) # The name of this script without extension ie: name
CWD=${BINDIR##*/} # The current directory name without the path ie: users
cd "$BINDIR"
pth="" # The path to the server root
name="" # The level name of the server
pth=$(grep -oP "path:K(.+)/([^/]+)" ./tasks.txt -s)
echo "path=$pth" > log.txt
shell-script error-handling
New contributor
Stuperfied is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
Note: I have a work around for this but feel that I shouldn't need it.
The following errors silently when typed into terminal
grep -oP "path:K(.+)/([^/]+)" ./tasks.txt -s
In a script file, the following will throw No such file or directory
pth=$(grep -oP "path:K(.+)/([^/]+)" ./tasks.txt -s)
grep: ./tasks.txt: No such file or directory
Why is the -s not working and how can the error be silenced?
Only just started when I ran into this error, here is my code so far.
#!/bin/bash
BINDIR=$(dirname "$(readlink -fn "$0")") # The curent directory path ie: /server/users/
SCR=$(basename -- "$0") # The name of this script ie: name.sh
SCRBASE=$(basename -- "$0" .sh) # The name of this script without extension ie: name
CWD=${BINDIR##*/} # The current directory name without the path ie: users
cd "$BINDIR"
pth="" # The path to the server root
name="" # The level name of the server
pth=$(grep -oP "path:K(.+)/([^/]+)" ./tasks.txt -s)
echo "path=$pth" > log.txt
shell-script error-handling
shell-script error-handling
New contributor
Stuperfied is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
New contributor
Stuperfied is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
edited 38 mins ago
New contributor
Stuperfied is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
asked 1 hour ago
Stuperfied
12
12
New contributor
Stuperfied is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
New contributor
Stuperfied is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
Stuperfied is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
Are you sure the error message comes from that line?
– nohillside
1 hour ago
Does it work if you change the script tocdto a handcoded directory name and assigningpth(so that the script only contains the shebang and two lines of code)?
– nohillside
1 hour ago
@nohillside Nope. Also, the file does not actually exist. afaik the -s should be working but is not.
– Stuperfied
50 mins ago
I suspected one of the other lines to throw the error, actually :-) Can you add the full error message (the whole line) to make this clear?
– nohillside
42 mins ago
@nohillside Added the full error to the post.
– Stuperfied
37 mins ago
|
show 1 more comment
Are you sure the error message comes from that line?
– nohillside
1 hour ago
Does it work if you change the script tocdto a handcoded directory name and assigningpth(so that the script only contains the shebang and two lines of code)?
– nohillside
1 hour ago
@nohillside Nope. Also, the file does not actually exist. afaik the -s should be working but is not.
– Stuperfied
50 mins ago
I suspected one of the other lines to throw the error, actually :-) Can you add the full error message (the whole line) to make this clear?
– nohillside
42 mins ago
@nohillside Added the full error to the post.
– Stuperfied
37 mins ago
Are you sure the error message comes from that line?
– nohillside
1 hour ago
Are you sure the error message comes from that line?
– nohillside
1 hour ago
Does it work if you change the script to
cd to a handcoded directory name and assigning pth (so that the script only contains the shebang and two lines of code)?– nohillside
1 hour ago
Does it work if you change the script to
cd to a handcoded directory name and assigning pth (so that the script only contains the shebang and two lines of code)?– nohillside
1 hour ago
@nohillside Nope. Also, the file does not actually exist. afaik the -s should be working but is not.
– Stuperfied
50 mins ago
@nohillside Nope. Also, the file does not actually exist. afaik the -s should be working but is not.
– Stuperfied
50 mins ago
I suspected one of the other lines to throw the error, actually :-) Can you add the full error message (the whole line) to make this clear?
– nohillside
42 mins ago
I suspected one of the other lines to throw the error, actually :-) Can you add the full error message (the whole line) to make this clear?
– nohillside
42 mins ago
@nohillside Added the full error to the post.
– Stuperfied
37 mins ago
@nohillside Added the full error to the post.
– Stuperfied
37 mins ago
|
show 1 more comment
active
oldest
votes
active
oldest
votes
active
oldest
votes
active
oldest
votes
active
oldest
votes
Stuperfied is a new contributor. Be nice, and check out our Code of Conduct.
Stuperfied is a new contributor. Be nice, and check out our Code of Conduct.
Stuperfied is a new contributor. Be nice, and check out our Code of Conduct.
Stuperfied is a new contributor. Be nice, and check out our Code of Conduct.
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%2funix.stackexchange.com%2fquestions%2f482088%2fhow-to-silence-grep-errors-when-used-with-a-variable%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
Are you sure the error message comes from that line?
– nohillside
1 hour ago
Does it work if you change the script to
cdto a handcoded directory name and assigningpth(so that the script only contains the shebang and two lines of code)?– nohillside
1 hour ago
@nohillside Nope. Also, the file does not actually exist. afaik the -s should be working but is not.
– Stuperfied
50 mins ago
I suspected one of the other lines to throw the error, actually :-) Can you add the full error message (the whole line) to make this clear?
– nohillside
42 mins ago
@nohillside Added the full error to the post.
– Stuperfied
37 mins ago