Write a regular expression which catches user $HOME in shellscripting The Next CEO of Stack...
Creating a script with console commands
How do I secure a TV wall mount?
How to pronounce fünf in 45
Why did the Drakh emissary look so blurred in S04:E11 "Lines of Communication"?
Is it a bad idea to plug the other end of ESD strap to wall ground?
Cannot restore registry to default in Windows 10?
Masking layers by a vector polygon layer in QGIS
What day is it again?
Salesforce opportunity stages
Strange use of "whether ... than ..." in official text
My ex-girlfriend uses my Apple ID to login to her iPad, do I have to give her my Apple ID password to reset it?
Why did early computer designers eschew integers?
It it possible to avoid kiwi.com's automatic online check-in and instead do it manually by yourself?
Prodigo = pro + ago?
Is a distribution that is normal, but highly skewed, considered Gaussian?
Direct Implications Between USA and UK in Event of No-Deal Brexit
How seriously should I take size and weight limits of hand luggage?
What is the difference between 'contrib' and 'non-free' packages repositories?
Is it OK to decorate a log book cover?
Gauss' Posthumous Publications?
Is a linearly independent set whose span is dense a Schauder basis?
Is it reasonable to ask other researchers to send me their previous grant applications?
Can this transistor (2n2222) take 6V on emitter-base? Am I reading datasheet incorrectly?
What are the unusually-enlarged wing sections on this P-38 Lightning?
Write a regular expression which catches user $HOME in shellscripting
The Next CEO of Stack OverflowProblem with script substitution when running scriptRegular expressionawk: runaway regular expressionuse of patterns symbol in regular expressionBash regular expressionpatterns symbol in regular expressionRegular expression to pull db table names from .sql filesRegex pwd for regular expressionregular expression that would catch 2 word in a stringCreate bash script that allows you to choose multiple options instead of just one?
I'd like to write a regex in shellscript which would compare the user input path to user$HOME. Then it would raise an error in case the user input path contains the user $HOME. The home folder normally starts with /ort/home but /ort part is not a must. When I run it always gives a valid path although I clearly enter an invalid path. What am I doing wrong? Thanks. Please refer following link[1] if necessary to see how regex are used in shellscript
My attempt is as follows
#!/bin/bash
function user_input () {
read -p "Type the path for project1:" user_path
string1="${HOME}"
echo "$string1"
if [ "$user_path" = "$string1 | /ort/home/+.* | .*+/home/+.*" ]; then
echo "Not a valid path, contains $HOME directory"
else
echo "valid path"
fi
}
function main() {
user_input
}
main
Terminal output
Please note first entry is a valid path and other two are invalid paths.
jenny@server32:~$ ./test.sh
Type the path for project1:/scratch/random
/ort/home/j/jen
valid path
jenny@server32:~$ ./test.sh
Type the path for project1:/ort/home/j/jen
/ort/home/j/jen
valid path
jenny@server32:~$ ./test.sh
Type the path for project1:/ort/home
/ort/home/j/jen
valid path
[1]https://stackoverflow.com/questions/2237080/how-to-compare-strings-in-bash
command-line bash scripts regex
add a comment |
I'd like to write a regex in shellscript which would compare the user input path to user$HOME. Then it would raise an error in case the user input path contains the user $HOME. The home folder normally starts with /ort/home but /ort part is not a must. When I run it always gives a valid path although I clearly enter an invalid path. What am I doing wrong? Thanks. Please refer following link[1] if necessary to see how regex are used in shellscript
My attempt is as follows
#!/bin/bash
function user_input () {
read -p "Type the path for project1:" user_path
string1="${HOME}"
echo "$string1"
if [ "$user_path" = "$string1 | /ort/home/+.* | .*+/home/+.*" ]; then
echo "Not a valid path, contains $HOME directory"
else
echo "valid path"
fi
}
function main() {
user_input
}
main
Terminal output
Please note first entry is a valid path and other two are invalid paths.
jenny@server32:~$ ./test.sh
Type the path for project1:/scratch/random
/ort/home/j/jen
valid path
jenny@server32:~$ ./test.sh
Type the path for project1:/ort/home/j/jen
/ort/home/j/jen
valid path
jenny@server32:~$ ./test.sh
Type the path for project1:/ort/home
/ort/home/j/jen
valid path
[1]https://stackoverflow.com/questions/2237080/how-to-compare-strings-in-bash
command-line bash scripts regex
add a comment |
I'd like to write a regex in shellscript which would compare the user input path to user$HOME. Then it would raise an error in case the user input path contains the user $HOME. The home folder normally starts with /ort/home but /ort part is not a must. When I run it always gives a valid path although I clearly enter an invalid path. What am I doing wrong? Thanks. Please refer following link[1] if necessary to see how regex are used in shellscript
My attempt is as follows
#!/bin/bash
function user_input () {
read -p "Type the path for project1:" user_path
string1="${HOME}"
echo "$string1"
if [ "$user_path" = "$string1 | /ort/home/+.* | .*+/home/+.*" ]; then
echo "Not a valid path, contains $HOME directory"
else
echo "valid path"
fi
}
function main() {
user_input
}
main
Terminal output
Please note first entry is a valid path and other two are invalid paths.
jenny@server32:~$ ./test.sh
Type the path for project1:/scratch/random
/ort/home/j/jen
valid path
jenny@server32:~$ ./test.sh
Type the path for project1:/ort/home/j/jen
/ort/home/j/jen
valid path
jenny@server32:~$ ./test.sh
Type the path for project1:/ort/home
/ort/home/j/jen
valid path
[1]https://stackoverflow.com/questions/2237080/how-to-compare-strings-in-bash
command-line bash scripts regex
I'd like to write a regex in shellscript which would compare the user input path to user$HOME. Then it would raise an error in case the user input path contains the user $HOME. The home folder normally starts with /ort/home but /ort part is not a must. When I run it always gives a valid path although I clearly enter an invalid path. What am I doing wrong? Thanks. Please refer following link[1] if necessary to see how regex are used in shellscript
My attempt is as follows
#!/bin/bash
function user_input () {
read -p "Type the path for project1:" user_path
string1="${HOME}"
echo "$string1"
if [ "$user_path" = "$string1 | /ort/home/+.* | .*+/home/+.*" ]; then
echo "Not a valid path, contains $HOME directory"
else
echo "valid path"
fi
}
function main() {
user_input
}
main
Terminal output
Please note first entry is a valid path and other two are invalid paths.
jenny@server32:~$ ./test.sh
Type the path for project1:/scratch/random
/ort/home/j/jen
valid path
jenny@server32:~$ ./test.sh
Type the path for project1:/ort/home/j/jen
/ort/home/j/jen
valid path
jenny@server32:~$ ./test.sh
Type the path for project1:/ort/home
/ort/home/j/jen
valid path
[1]https://stackoverflow.com/questions/2237080/how-to-compare-strings-in-bash
command-line bash scripts regex
command-line bash scripts regex
asked 6 mins ago
JennyJenny
845
845
add a comment |
add a comment |
0
active
oldest
votes
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "89"
};
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',
autoActivateHeartbeat: false,
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%2faskubuntu.com%2fquestions%2f1130471%2fwrite-a-regular-expression-which-catches-user-home-in-shellscripting%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
0
active
oldest
votes
0
active
oldest
votes
active
oldest
votes
active
oldest
votes
Thanks for contributing an answer to Ask Ubuntu!
- 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%2faskubuntu.com%2fquestions%2f1130471%2fwrite-a-regular-expression-which-catches-user-home-in-shellscripting%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
