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?
Why did early computer designers eschew integers?
How can I separate the number from the unit in argument?
Can this transistor (2n2222) take 6V on emitter-base? Am I reading datasheet incorrectly?
How should I connect my cat5 cable to connectors having an orange-green line?
Masking layers by a vector polygon layer in QGIS
pgfplots: How to draw a tangent graph below two others?
Is there a rule of thumb for determining the amount one should accept for of a settlement offer?
logical reads on global temp table, but not on session-level temp table
Is a distribution that is normal, but highly skewed, considered Gaussian?
Strange use of "whether ... than ..." in official text
MT "will strike" & LXX "will watch carefully" (Gen 3:15)?
Compensation for working overtime on Saturdays
How to find if SQL server backup is encrypted with TDE without restoring the backup
How to unfasten electrical subpanel attached with ramset
Is it reasonable to ask other researchers to send me their previous grant applications?
Why do we say “un seul M” and not “une seule M” even though M is a “consonne”?
Compilation of a 2d array and a 1d array
Physiological effects of huge anime eyes
Does Germany produce more waste than the US?
Another proof that dividing by 0 does not exist -- is it right?
The sum of any ten consecutive numbers from a fibonacci sequence is divisible by 11
Variance of Monte Carlo integration with importance sampling
Salesforce opportunity stages
Traveling with my 5 year old daughter (as the father) without the mother from Germany to Mexico
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
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
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
1
Regular expression comparison and string (glob pattern) comparison are different things, with different operators in bash (=~versus==or=); additionally,=~is only supported within extended test brackets[[ ... ]]afaik
– steeldriver
1 hour ago
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
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
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 1 hour ago
JennyJenny
846
846
1
Regular expression comparison and string (glob pattern) comparison are different things, with different operators in bash (=~versus==or=); additionally,=~is only supported within extended test brackets[[ ... ]]afaik
– steeldriver
1 hour ago
add a comment |
1
Regular expression comparison and string (glob pattern) comparison are different things, with different operators in bash (=~versus==or=); additionally,=~is only supported within extended test brackets[[ ... ]]afaik
– steeldriver
1 hour ago
1
1
Regular expression comparison and string (glob pattern) comparison are different things, with different operators in bash (
=~ versus == or =); additionally, =~ is only supported within extended test brackets [[ ... ]] afaik– steeldriver
1 hour ago
Regular expression comparison and string (glob pattern) comparison are different things, with different operators in bash (
=~ versus == or =); additionally, =~ is only supported within extended test brackets [[ ... ]] afaik– steeldriver
1 hour ago
add a comment |
1 Answer
1
active
oldest
votes
The case command uses glob wildcards which are pretty easy to work with:
case "$user_path" in
"$HOME"*) echo "Error: path cannot be in your HOME" ;;
*/home/*) echo "Error: cannot have 'home' in the path" ;;
*) echo "Thank you, valid path" ;;
esac
Thanks! It works smoothly. Jen
– Jenny
48 mins ago
add a comment |
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
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
The case command uses glob wildcards which are pretty easy to work with:
case "$user_path" in
"$HOME"*) echo "Error: path cannot be in your HOME" ;;
*/home/*) echo "Error: cannot have 'home' in the path" ;;
*) echo "Thank you, valid path" ;;
esac
Thanks! It works smoothly. Jen
– Jenny
48 mins ago
add a comment |
The case command uses glob wildcards which are pretty easy to work with:
case "$user_path" in
"$HOME"*) echo "Error: path cannot be in your HOME" ;;
*/home/*) echo "Error: cannot have 'home' in the path" ;;
*) echo "Thank you, valid path" ;;
esac
Thanks! It works smoothly. Jen
– Jenny
48 mins ago
add a comment |
The case command uses glob wildcards which are pretty easy to work with:
case "$user_path" in
"$HOME"*) echo "Error: path cannot be in your HOME" ;;
*/home/*) echo "Error: cannot have 'home' in the path" ;;
*) echo "Thank you, valid path" ;;
esac
The case command uses glob wildcards which are pretty easy to work with:
case "$user_path" in
"$HOME"*) echo "Error: path cannot be in your HOME" ;;
*/home/*) echo "Error: cannot have 'home' in the path" ;;
*) echo "Thank you, valid path" ;;
esac
answered 54 mins ago
glenn jackmanglenn jackman
12.7k2545
12.7k2545
Thanks! It works smoothly. Jen
– Jenny
48 mins ago
add a comment |
Thanks! It works smoothly. Jen
– Jenny
48 mins ago
Thanks! It works smoothly. Jen
– Jenny
48 mins ago
Thanks! It works smoothly. Jen
– Jenny
48 mins ago
add a comment |
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

1
Regular expression comparison and string (glob pattern) comparison are different things, with different operators in bash (
=~versus==or=); additionally,=~is only supported within extended test brackets[[ ... ]]afaik– steeldriver
1 hour ago