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?










-1















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










share|improve this question

















  • 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















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










share|improve this question

















  • 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








-1








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










share|improve this question














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






share|improve this question













share|improve this question











share|improve this question




share|improve this question










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












  • 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










1 Answer
1






active

oldest

votes


















2














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





share|improve this answer























  • Thanks! It works smoothly. Jen

    – Jenny
    48 mins ago











Your Answer








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
);



);













draft saved

draft discarded


















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









2














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





share|improve this answer























  • Thanks! It works smoothly. Jen

    – Jenny
    48 mins ago















2














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





share|improve this answer























  • Thanks! It works smoothly. Jen

    – Jenny
    48 mins ago













2












2








2







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





share|improve this answer













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






share|improve this answer












share|improve this answer



share|improve this answer










answered 54 mins ago









glenn jackmanglenn jackman

12.7k2545




12.7k2545












  • 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





Thanks! It works smoothly. Jen

– Jenny
48 mins ago

















draft saved

draft discarded
















































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.




draft saved


draft discarded














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





















































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







Popular posts from this blog

Are there any comparative studies done between Ashtavakra Gita and Buddhim?How is it wrong to believe that a self exists, or that it doesn't?Can you criticise or improve Ven. Bodhi's description of MahayanaWas the doctrine of 'Anatta', accepted as doctrine by modern Buddhism, actually taught by the Buddha?Relationship between Buddhism, Hinduism and Yoga?Comparison of Nirvana, Tao and Brahman/AtmaIs there a distinction between “ego identity” and “craving/hating”?Are there many differences between Taoism and Buddhism?Loss of “faith” in buddhismSimilarity between creation in Abrahamic religions and beginning of life in Earth mentioned Agganna Sutta?Are there studies about the difference between meditating in the morning versus in the evening?Can one follow Hinduism and Buddhism at the same time?Are there any prohibitions on participating in other religion's practices?Psychology of 'flow'

fallocate: fallocate failed: Text file busy in Ubuntu 17.04? Announcing the arrival of Valued Associate #679: Cesar Manara Planned maintenance scheduled April 17/18, 2019 at 00:00UTC (8:00pm US/Eastern)defragmenting and increasing performance of old lubuntu system with swap partitionIssue with increasing the root partition from the swapthis /usr/bin/dpkg returned error || ubuntu-16.04, 64bitDefault 17.04 swap file locationHow to Resize Ubuntu 17.04 Zesty Swap file size?Ubuntu freezes from online formsMy Laptop is not starting after upgrade ubuntu 16.04 (Kernel 4.8.0-38 to 04.10.0-36)hcp: ERROR: FALLOCATE FAILED!Not sure my swap is being usedWine 3.0 asking for more virtual free swap

Where is the suspend/hibernate button in GNOME Shell? Announcing the arrival of Valued Associate #679: Cesar Manara Planned maintenance scheduled April 23, 2019 at 23:30 UTC (7:30pm US/Eastern)No suspend option in UI on Bionic BeaverHow can I set sleep mode in ubuntu18.04 LTS and what is the short cut key to do so?17.10 suspend not availableUbuntu 18.04 LTS missing sleep optionUbuntu 18.04 LTS - missing suspend option when power button is pressedHow to put Thinkpad X1 Extreme to sleep in Ubuntu 18.10?Suspend Button in interactive power button menu18.04 - Keep programs running after logging outway to disable Hibernate from within gconf-editor so button disappears?How can I hibernate from GNOME Shell?How can I hibernate/suspend from the command line and do so at a specific timeNo permission to suspend/hibernate after upgrading to 12.10MATE - Missing Suspend and Hibernate buttons, pressing power button shutdowns system immediatelyUbuntu 14.04: Suspend, Hibernate and Suspend-hybrid in the menu?Change “power-button-action” comand for “hibernate” option in GNOME 3.18Shutdown / Power off button does always go to suspend on 17.10Hibernate after suspend stopped working in 17.10Why doesn't the keyboard screenshot button work on Ubuntu with GNOME shell?