Write a function that checks if a string starts with or contains somethingHow to pass a string parameter on bash function?Function that calls another function with list of arguments doesn't workHow do i create a function to test if the input contains any character?A basic function that doesn't workVIM: function that checks if external program is runningTerminal emulator crashes with function with nested case statements?Test if a string contains a substringCall function that call ffmpeg in loopShell: Using function with parameters in ifDetermining if the first string starts with second string

Why can my keyboard only digest 6 keypresses at a time?

How to learn Linux system internals

Russian word for a male zebra

Can I utilise a baking stone to make crepes?

Write a function that checks if a string starts with or contains something

Why was this person allowed to become Grand Maester?

Are inverted question and exclamation mark supposed to be symmetrical to the "normal" counter-parts?

Advantages of the Exponential Family: why should we study it and use it?

Can a human be transformed into a Mind Flayer?

Why did Intel abandon unified CPU cache?

What are some really overused phrases in French that are common nowadays?

Is it possible to have 2 different but equal size real number sets that have the same mean and standard deviation?

Why are MBA programs closing in the United States?

A word that means "blending into a community too much"

Separate SPI data

How to safely destroy (a large quantity of) valid checks?

Generate basis elements of the Steenrod algebra

How can I remove material from this wood beam?

Who won a Game of Bar Dice?

Is it possible to fly backward if you have really strong headwind?

Solve Riddle With Algebra

Can all groups be thought of as the symmetries of a geometrical object?

Is it possible for a vehicle to be manufactured without a catalytic converter?

If I leave the US through an airport, do I have to return through the same airport?



Write a function that checks if a string starts with or contains something


How to pass a string parameter on bash function?Function that calls another function with list of arguments doesn't workHow do i create a function to test if the input contains any character?A basic function that doesn't workVIM: function that checks if external program is runningTerminal emulator crashes with function with nested case statements?Test if a string contains a substringCall function that call ffmpeg in loopShell: Using function with parameters in ifDetermining if the first string starts with second string






.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty margin-bottom:0;








1















I want to write a function that checks if a given variable, say, var, starts with any of the words in a given list of strings. This list won't change.



To instantiate, let's pretend that I want to check if var starts with aa, abc or 3@3.



Moreover, I want to check if var contains the character >.



Let's say this function is called check_func. My intended usage looks something like



if check_func "$var"; then
do stuff
fi


For example, it should "do stuff" for
aardvark, abcdef, 3@3com.com and 12>5.




I've seen this SO question where a user provides part of the work:



beginswith() case $2 in "$1"*) true;; *) false;; esac; 


My idea is that I would iterate over the list mentioned above and use this function. My difficulty lies in not understanding exactly how exiting (or whatever replaces returning) should be done to make this work.










share|improve this question









New contributor



No Imaginatition is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.



















  • It just occurred to me that your question is ambiguous.  Do you mean (1) I want to check if var starts with aa.  I want to check if var starts with abc.  I want to check if var starts with 3@3.  And I want to check if var contains >. ?    Or do you mean (2) I want to check if var starts with aa, abc or 3@3, and it also contains >. ?

    – G-Man
    7 hours ago












  • @G-Man The first one. Thanks for bringing that up.

    – No Imaginatition
    6 hours ago

















1















I want to write a function that checks if a given variable, say, var, starts with any of the words in a given list of strings. This list won't change.



To instantiate, let's pretend that I want to check if var starts with aa, abc or 3@3.



Moreover, I want to check if var contains the character >.



Let's say this function is called check_func. My intended usage looks something like



if check_func "$var"; then
do stuff
fi


For example, it should "do stuff" for
aardvark, abcdef, 3@3com.com and 12>5.




I've seen this SO question where a user provides part of the work:



beginswith() case $2 in "$1"*) true;; *) false;; esac; 


My idea is that I would iterate over the list mentioned above and use this function. My difficulty lies in not understanding exactly how exiting (or whatever replaces returning) should be done to make this work.










share|improve this question









New contributor



No Imaginatition is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.



















  • It just occurred to me that your question is ambiguous.  Do you mean (1) I want to check if var starts with aa.  I want to check if var starts with abc.  I want to check if var starts with 3@3.  And I want to check if var contains >. ?    Or do you mean (2) I want to check if var starts with aa, abc or 3@3, and it also contains >. ?

    – G-Man
    7 hours ago












  • @G-Man The first one. Thanks for bringing that up.

    – No Imaginatition
    6 hours ago













1












1








1


1






I want to write a function that checks if a given variable, say, var, starts with any of the words in a given list of strings. This list won't change.



To instantiate, let's pretend that I want to check if var starts with aa, abc or 3@3.



Moreover, I want to check if var contains the character >.



Let's say this function is called check_func. My intended usage looks something like



if check_func "$var"; then
do stuff
fi


For example, it should "do stuff" for
aardvark, abcdef, 3@3com.com and 12>5.




I've seen this SO question where a user provides part of the work:



beginswith() case $2 in "$1"*) true;; *) false;; esac; 


My idea is that I would iterate over the list mentioned above and use this function. My difficulty lies in not understanding exactly how exiting (or whatever replaces returning) should be done to make this work.










share|improve this question









New contributor



No Imaginatition is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.











I want to write a function that checks if a given variable, say, var, starts with any of the words in a given list of strings. This list won't change.



To instantiate, let's pretend that I want to check if var starts with aa, abc or 3@3.



Moreover, I want to check if var contains the character >.



Let's say this function is called check_func. My intended usage looks something like



if check_func "$var"; then
do stuff
fi


For example, it should "do stuff" for
aardvark, abcdef, 3@3com.com and 12>5.




I've seen this SO question where a user provides part of the work:



beginswith() case $2 in "$1"*) true;; *) false;; esac; 


My idea is that I would iterate over the list mentioned above and use this function. My difficulty lies in not understanding exactly how exiting (or whatever replaces returning) should be done to make this work.







shell string function pattern-matching






share|improve this question









New contributor



No Imaginatition is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.










share|improve this question









New contributor



No Imaginatition is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.








share|improve this question




share|improve this question








edited 30 mins ago









G-Man

14.6k94175




14.6k94175






New contributor



No Imaginatition is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.








asked 9 hours ago









No ImaginatitionNo Imaginatition

83




83




New contributor



No Imaginatition is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.




New contributor




No Imaginatition is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.














  • It just occurred to me that your question is ambiguous.  Do you mean (1) I want to check if var starts with aa.  I want to check if var starts with abc.  I want to check if var starts with 3@3.  And I want to check if var contains >. ?    Or do you mean (2) I want to check if var starts with aa, abc or 3@3, and it also contains >. ?

    – G-Man
    7 hours ago












  • @G-Man The first one. Thanks for bringing that up.

    – No Imaginatition
    6 hours ago

















  • It just occurred to me that your question is ambiguous.  Do you mean (1) I want to check if var starts with aa.  I want to check if var starts with abc.  I want to check if var starts with 3@3.  And I want to check if var contains >. ?    Or do you mean (2) I want to check if var starts with aa, abc or 3@3, and it also contains >. ?

    – G-Man
    7 hours ago












  • @G-Man The first one. Thanks for bringing that up.

    – No Imaginatition
    6 hours ago
















It just occurred to me that your question is ambiguous.  Do you mean (1) I want to check if var starts with aa.  I want to check if var starts with abc.  I want to check if var starts with 3@3.  And I want to check if var contains >. ?    Or do you mean (2) I want to check if var starts with aa, abc or 3@3, and it also contains >. ?

– G-Man
7 hours ago






It just occurred to me that your question is ambiguous.  Do you mean (1) I want to check if var starts with aa.  I want to check if var starts with abc.  I want to check if var starts with 3@3.  And I want to check if var contains >. ?    Or do you mean (2) I want to check if var starts with aa, abc or 3@3, and it also contains >. ?

– G-Man
7 hours ago














@G-Man The first one. Thanks for bringing that up.

– No Imaginatition
6 hours ago





@G-Man The first one. Thanks for bringing that up.

– No Imaginatition
6 hours ago










5 Answers
5






active

oldest

votes


















4














check_prefixes () 
value=$1

for prefix in aa abc 3@3; do
case $value in
"$prefix"*) return 0
esac
done

return 1


check_contains_gt ()
value=$1

case $value in
*">"*) return 0
esac

return 1


var='aa>'
if check_prefixes "$var" && check_contains_gt "$var"; then
printf '"%s" contains ">" and starts with one of the prefixesn' "$var"
fi


I divided the tests up into two functions. Both use case ... esac and returns success (zero) as soon as this can be determined. If nothing matches, failure (1) is returned.



To make the list of prefixes more of a dynamic list, one could possibly write the first function as



check_prefixes () 
value=$1
shift

for prefix do
case $value in
"$prefix"*) return 0
esac
done

return 1



(the value to inspect is the first argument, which we save in value and then shift off the list of arguments to the function; we then iterate over the remaining arguments) and then call it as



check_prefixes "$var" aa abc 3@3


The second function could be changed in a similar manner, into



check_contains () 
value=$1
shift

case $value in
*"$1"*) return 0
esac

return 1



(to check for some arbitrary substring), or



check_contains_oneof () 
value=$1
shift

for substring do
case $value in
*"$substring"*) return 0
esac
done

return 1



(to check for any of a number of substrings)






share|improve this answer

























  • Thanks. My intended logic is with a logical or instead of a logical and. Should it be value instead of var in the first function's definition?

    – No Imaginatition
    5 hours ago











  • @NoImaginatition OK, just change the logic in the code calling the functions (|| instead of &&). Yes, that's a typo in my code, I'll fix it at once, thanks.

    – Kusalananda
    5 hours ago











  • I'm trying to combine both functions into one by defining check_func() , but it won't work for echo a >file. Any idea why?

    – No Imaginatition
    5 hours ago











  • @NoImaginatition Always double quote variable expansions ("$1") unless you know exactly in what contexts this is not needed.

    – Kusalananda
    5 hours ago











  • Great, it worked. If it's not much to ask, what is it that it makes it fail without the double quotes? I tried to test if it would expand the second call of $1, and it seems to expand. I tested it with test () echo $1 $1; and it worked fine.

    – No Imaginatition
    5 hours ago


















1














For bash:



Using the properties of regex you can write start with ^ and contain by nothing.



The list of regexes to check start with aa abc or 3@3 and contains > is:



^aa ^abc ^3@3 >


Make that a properly quoted list and ask bash to use regexes (=~):



check_func() 
matched=1
for test_regex in '^aa' '^abc' '^3@3' '>'; do
if [[ $var =~ $test_regex ]] ; then
matched=0
break
fi
done
return "$matched"


var='aaIsAMatch'
if check_func; then
echo "A match was found"
fi


The function has hard-coded the list of matches and the name of the var.



Giving the list of regex in an array variable and the value to test on the first argument:



check_func() 
local matched; matched=1
for t in "$test_regex[@]"; do
[[ $1 =~ $t ]] && matched=0; break;
done
return "$matched"



test_regex=('^aa' '^abc' '^3@3' '>')

if check_func 'aaIsAMatch'; then
echo "A match was found"
fi


The function could be further improved to use the name of a variable (instead of a value) as the first argument.



posix



As there is no regex in posix shells and the only way to test is a case statement, we must use a case statement. Sadly, for older shells ([no extended globs available][1]) we must loop to make all tests. And, the globs need to be:



'aa*' 'abc*' '3@3*' '*>*'


An script example that tests several input strings against several globs:



check_func() :
matched=1
value=$1; shift
for t in "$@"; do
case $value in $t) matched=0; #break;; esac
echo "matched $value with $t"
;;
esac
done
return "$matched"



for var in abdg wabcde aadef abcde 3@3hello hmm3@3hell 'we>we' 'a>dfff' 'dfd>' 'a> de' 'a*> fg'; do
if check_func "$var" 'aa*' 'abc*' '3@3*' '*>*'; then
echo "========A match was found for "$var""
fi
done


A simpler version of the function to exactly match your request:



check_func() :
matched=1
value=$1; shift
for t in "$@"; do
case $value in $t) matched=0; break;; esac
done
return "$matched"






share|improve this answer
































    1














    Revised based on clarification to the question:
    This is less elegant (and much less flexible),
    but more compact than the other answers,



    check_func() abc* 


    This returns true for aardvark, abcdef, 3@3com.com and 12>5
    And, of course, also aard>vark, abc<def>ghi and 3@3>3.






    share|improve this answer
































      0














      Here's what the case statement does: take the second parameter to the function ($2). If it matches the pattern "$1"*, i.e. the first argument to the function followed by anything, then execute true and end the case statement. true does nothing and returns the status 0. Otherwise, if it matches *, i.e. anything, execute false and end the case statement. false does nothing and returns the status 1. Thus the case statement has the status 0 if the second parameter starts with the first parameter and 1 otherwise. Since this is the last (and only) statement in the function, the function returns 0 if the second parameter starts with the first parameter and 1 otherwise.



      Conditional statements such as if in the shell consider a statement to be true if it returns 0 and false otherwise. Hence if beginswith "$var" "string"; then echo yes; else echo no; fi prints yes if the value of var starts with string and no otherwise.



      There are several alternative ways to write this function. For example the author could have used return 0 or return 1 instead of true and false, since they are the last statement in the function. The way the function was written makes it possible to use its body directly without wrapping it in a function, by just changing references to the function parameters ($1 and $2) to whatever strings you want to work with.



      To allow multiple prefixes, iterate over them in a loop. As soon as you've found a matching prefix, return from the function, with a true status (0). If none of the prefixes match, return a false status (conventionally 1).



      # begins_with STRING PREFIX1 PREFIX2...
      # Test if STRING starts with any of PREFIX1, PREFIX2, ...
      begins_with ()
      string=$1
      shift
      for prefix in "$@"; do
      case "$string" in
      "$prefix"*) return 0;;
      esac
      done
      return 1


      if begins_with "$var" 'aa' 'abc' '3@3'; then
      echo "The value starts with one of the permitted prefixes"
      fi


      To test for a suffix, use the pattern *"$suffix" instead of "$prefix"*. To test for a substring, use *"$substring"*. Note that the double quotes are necessary here, otherwise the variable would be interpreted as a pattern. For example:



      suffix='?'
      case "$var" in
      *"$suffix") echo "The value of var ends with a question mark";;
      esac
      case "$var" in
      *$suffix) echo "The value of var is not empty";;
      esac





      share|improve this answer






























        0














        For anything involving text manipulation, Python is going to be far easier to write in:



        check_func()
        python -c "from sys import exit; exit(0) if any(['$1'.startswith(x) for x in ('aa', 'abc', '3@3')]) and '>' in '$1' else exit(1)"



        I use it for all my bash scripts now even the kind that call lots of other programs and reads their results. It's just so much easier and doesn't suffer from weird errors like Bash seems too.






        share|improve this answer

























          Your Answer








          StackExchange.ready(function()
          var channelOptions =
          tags: "".split(" "),
          id: "106"
          ;
          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: false,
          noModals: true,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: null,
          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
          );



          );






          No Imaginatition is a new contributor. Be nice, and check out our Code of Conduct.









          draft saved

          draft discarded


















          StackExchange.ready(
          function ()
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f523625%2fwrite-a-function-that-checks-if-a-string-starts-with-or-contains-something%23new-answer', 'question_page');

          );

          Post as a guest















          Required, but never shown

























          5 Answers
          5






          active

          oldest

          votes








          5 Answers
          5






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes









          4














          check_prefixes () 
          value=$1

          for prefix in aa abc 3@3; do
          case $value in
          "$prefix"*) return 0
          esac
          done

          return 1


          check_contains_gt ()
          value=$1

          case $value in
          *">"*) return 0
          esac

          return 1


          var='aa>'
          if check_prefixes "$var" && check_contains_gt "$var"; then
          printf '"%s" contains ">" and starts with one of the prefixesn' "$var"
          fi


          I divided the tests up into two functions. Both use case ... esac and returns success (zero) as soon as this can be determined. If nothing matches, failure (1) is returned.



          To make the list of prefixes more of a dynamic list, one could possibly write the first function as



          check_prefixes () 
          value=$1
          shift

          for prefix do
          case $value in
          "$prefix"*) return 0
          esac
          done

          return 1



          (the value to inspect is the first argument, which we save in value and then shift off the list of arguments to the function; we then iterate over the remaining arguments) and then call it as



          check_prefixes "$var" aa abc 3@3


          The second function could be changed in a similar manner, into



          check_contains () 
          value=$1
          shift

          case $value in
          *"$1"*) return 0
          esac

          return 1



          (to check for some arbitrary substring), or



          check_contains_oneof () 
          value=$1
          shift

          for substring do
          case $value in
          *"$substring"*) return 0
          esac
          done

          return 1



          (to check for any of a number of substrings)






          share|improve this answer

























          • Thanks. My intended logic is with a logical or instead of a logical and. Should it be value instead of var in the first function's definition?

            – No Imaginatition
            5 hours ago











          • @NoImaginatition OK, just change the logic in the code calling the functions (|| instead of &&). Yes, that's a typo in my code, I'll fix it at once, thanks.

            – Kusalananda
            5 hours ago











          • I'm trying to combine both functions into one by defining check_func() , but it won't work for echo a >file. Any idea why?

            – No Imaginatition
            5 hours ago











          • @NoImaginatition Always double quote variable expansions ("$1") unless you know exactly in what contexts this is not needed.

            – Kusalananda
            5 hours ago











          • Great, it worked. If it's not much to ask, what is it that it makes it fail without the double quotes? I tried to test if it would expand the second call of $1, and it seems to expand. I tested it with test () echo $1 $1; and it worked fine.

            – No Imaginatition
            5 hours ago















          4














          check_prefixes () 
          value=$1

          for prefix in aa abc 3@3; do
          case $value in
          "$prefix"*) return 0
          esac
          done

          return 1


          check_contains_gt ()
          value=$1

          case $value in
          *">"*) return 0
          esac

          return 1


          var='aa>'
          if check_prefixes "$var" && check_contains_gt "$var"; then
          printf '"%s" contains ">" and starts with one of the prefixesn' "$var"
          fi


          I divided the tests up into two functions. Both use case ... esac and returns success (zero) as soon as this can be determined. If nothing matches, failure (1) is returned.



          To make the list of prefixes more of a dynamic list, one could possibly write the first function as



          check_prefixes () 
          value=$1
          shift

          for prefix do
          case $value in
          "$prefix"*) return 0
          esac
          done

          return 1



          (the value to inspect is the first argument, which we save in value and then shift off the list of arguments to the function; we then iterate over the remaining arguments) and then call it as



          check_prefixes "$var" aa abc 3@3


          The second function could be changed in a similar manner, into



          check_contains () 
          value=$1
          shift

          case $value in
          *"$1"*) return 0
          esac

          return 1



          (to check for some arbitrary substring), or



          check_contains_oneof () 
          value=$1
          shift

          for substring do
          case $value in
          *"$substring"*) return 0
          esac
          done

          return 1



          (to check for any of a number of substrings)






          share|improve this answer

























          • Thanks. My intended logic is with a logical or instead of a logical and. Should it be value instead of var in the first function's definition?

            – No Imaginatition
            5 hours ago











          • @NoImaginatition OK, just change the logic in the code calling the functions (|| instead of &&). Yes, that's a typo in my code, I'll fix it at once, thanks.

            – Kusalananda
            5 hours ago











          • I'm trying to combine both functions into one by defining check_func() , but it won't work for echo a >file. Any idea why?

            – No Imaginatition
            5 hours ago











          • @NoImaginatition Always double quote variable expansions ("$1") unless you know exactly in what contexts this is not needed.

            – Kusalananda
            5 hours ago











          • Great, it worked. If it's not much to ask, what is it that it makes it fail without the double quotes? I tried to test if it would expand the second call of $1, and it seems to expand. I tested it with test () echo $1 $1; and it worked fine.

            – No Imaginatition
            5 hours ago













          4












          4








          4







          check_prefixes () 
          value=$1

          for prefix in aa abc 3@3; do
          case $value in
          "$prefix"*) return 0
          esac
          done

          return 1


          check_contains_gt ()
          value=$1

          case $value in
          *">"*) return 0
          esac

          return 1


          var='aa>'
          if check_prefixes "$var" && check_contains_gt "$var"; then
          printf '"%s" contains ">" and starts with one of the prefixesn' "$var"
          fi


          I divided the tests up into two functions. Both use case ... esac and returns success (zero) as soon as this can be determined. If nothing matches, failure (1) is returned.



          To make the list of prefixes more of a dynamic list, one could possibly write the first function as



          check_prefixes () 
          value=$1
          shift

          for prefix do
          case $value in
          "$prefix"*) return 0
          esac
          done

          return 1



          (the value to inspect is the first argument, which we save in value and then shift off the list of arguments to the function; we then iterate over the remaining arguments) and then call it as



          check_prefixes "$var" aa abc 3@3


          The second function could be changed in a similar manner, into



          check_contains () 
          value=$1
          shift

          case $value in
          *"$1"*) return 0
          esac

          return 1



          (to check for some arbitrary substring), or



          check_contains_oneof () 
          value=$1
          shift

          for substring do
          case $value in
          *"$substring"*) return 0
          esac
          done

          return 1



          (to check for any of a number of substrings)






          share|improve this answer















          check_prefixes () 
          value=$1

          for prefix in aa abc 3@3; do
          case $value in
          "$prefix"*) return 0
          esac
          done

          return 1


          check_contains_gt ()
          value=$1

          case $value in
          *">"*) return 0
          esac

          return 1


          var='aa>'
          if check_prefixes "$var" && check_contains_gt "$var"; then
          printf '"%s" contains ">" and starts with one of the prefixesn' "$var"
          fi


          I divided the tests up into two functions. Both use case ... esac and returns success (zero) as soon as this can be determined. If nothing matches, failure (1) is returned.



          To make the list of prefixes more of a dynamic list, one could possibly write the first function as



          check_prefixes () 
          value=$1
          shift

          for prefix do
          case $value in
          "$prefix"*) return 0
          esac
          done

          return 1



          (the value to inspect is the first argument, which we save in value and then shift off the list of arguments to the function; we then iterate over the remaining arguments) and then call it as



          check_prefixes "$var" aa abc 3@3


          The second function could be changed in a similar manner, into



          check_contains () 
          value=$1
          shift

          case $value in
          *"$1"*) return 0
          esac

          return 1



          (to check for some arbitrary substring), or



          check_contains_oneof () 
          value=$1
          shift

          for substring do
          case $value in
          *"$substring"*) return 0
          esac
          done

          return 1



          (to check for any of a number of substrings)







          share|improve this answer














          share|improve this answer



          share|improve this answer








          edited 5 hours ago

























          answered 8 hours ago









          KusalanandaKusalananda

          150k18286471




          150k18286471












          • Thanks. My intended logic is with a logical or instead of a logical and. Should it be value instead of var in the first function's definition?

            – No Imaginatition
            5 hours ago











          • @NoImaginatition OK, just change the logic in the code calling the functions (|| instead of &&). Yes, that's a typo in my code, I'll fix it at once, thanks.

            – Kusalananda
            5 hours ago











          • I'm trying to combine both functions into one by defining check_func() , but it won't work for echo a >file. Any idea why?

            – No Imaginatition
            5 hours ago











          • @NoImaginatition Always double quote variable expansions ("$1") unless you know exactly in what contexts this is not needed.

            – Kusalananda
            5 hours ago











          • Great, it worked. If it's not much to ask, what is it that it makes it fail without the double quotes? I tried to test if it would expand the second call of $1, and it seems to expand. I tested it with test () echo $1 $1; and it worked fine.

            – No Imaginatition
            5 hours ago

















          • Thanks. My intended logic is with a logical or instead of a logical and. Should it be value instead of var in the first function's definition?

            – No Imaginatition
            5 hours ago











          • @NoImaginatition OK, just change the logic in the code calling the functions (|| instead of &&). Yes, that's a typo in my code, I'll fix it at once, thanks.

            – Kusalananda
            5 hours ago











          • I'm trying to combine both functions into one by defining check_func() , but it won't work for echo a >file. Any idea why?

            – No Imaginatition
            5 hours ago











          • @NoImaginatition Always double quote variable expansions ("$1") unless you know exactly in what contexts this is not needed.

            – Kusalananda
            5 hours ago











          • Great, it worked. If it's not much to ask, what is it that it makes it fail without the double quotes? I tried to test if it would expand the second call of $1, and it seems to expand. I tested it with test () echo $1 $1; and it worked fine.

            – No Imaginatition
            5 hours ago
















          Thanks. My intended logic is with a logical or instead of a logical and. Should it be value instead of var in the first function's definition?

          – No Imaginatition
          5 hours ago





          Thanks. My intended logic is with a logical or instead of a logical and. Should it be value instead of var in the first function's definition?

          – No Imaginatition
          5 hours ago













          @NoImaginatition OK, just change the logic in the code calling the functions (|| instead of &&). Yes, that's a typo in my code, I'll fix it at once, thanks.

          – Kusalananda
          5 hours ago





          @NoImaginatition OK, just change the logic in the code calling the functions (|| instead of &&). Yes, that's a typo in my code, I'll fix it at once, thanks.

          – Kusalananda
          5 hours ago













          I'm trying to combine both functions into one by defining check_func() , but it won't work for echo a >file. Any idea why?

          – No Imaginatition
          5 hours ago





          I'm trying to combine both functions into one by defining check_func() , but it won't work for echo a >file. Any idea why?

          – No Imaginatition
          5 hours ago













          @NoImaginatition Always double quote variable expansions ("$1") unless you know exactly in what contexts this is not needed.

          – Kusalananda
          5 hours ago





          @NoImaginatition Always double quote variable expansions ("$1") unless you know exactly in what contexts this is not needed.

          – Kusalananda
          5 hours ago













          Great, it worked. If it's not much to ask, what is it that it makes it fail without the double quotes? I tried to test if it would expand the second call of $1, and it seems to expand. I tested it with test () echo $1 $1; and it worked fine.

          – No Imaginatition
          5 hours ago





          Great, it worked. If it's not much to ask, what is it that it makes it fail without the double quotes? I tried to test if it would expand the second call of $1, and it seems to expand. I tested it with test () echo $1 $1; and it worked fine.

          – No Imaginatition
          5 hours ago













          1














          For bash:



          Using the properties of regex you can write start with ^ and contain by nothing.



          The list of regexes to check start with aa abc or 3@3 and contains > is:



          ^aa ^abc ^3@3 >


          Make that a properly quoted list and ask bash to use regexes (=~):



          check_func() 
          matched=1
          for test_regex in '^aa' '^abc' '^3@3' '>'; do
          if [[ $var =~ $test_regex ]] ; then
          matched=0
          break
          fi
          done
          return "$matched"


          var='aaIsAMatch'
          if check_func; then
          echo "A match was found"
          fi


          The function has hard-coded the list of matches and the name of the var.



          Giving the list of regex in an array variable and the value to test on the first argument:



          check_func() 
          local matched; matched=1
          for t in "$test_regex[@]"; do
          [[ $1 =~ $t ]] && matched=0; break;
          done
          return "$matched"



          test_regex=('^aa' '^abc' '^3@3' '>')

          if check_func 'aaIsAMatch'; then
          echo "A match was found"
          fi


          The function could be further improved to use the name of a variable (instead of a value) as the first argument.



          posix



          As there is no regex in posix shells and the only way to test is a case statement, we must use a case statement. Sadly, for older shells ([no extended globs available][1]) we must loop to make all tests. And, the globs need to be:



          'aa*' 'abc*' '3@3*' '*>*'


          An script example that tests several input strings against several globs:



          check_func() :
          matched=1
          value=$1; shift
          for t in "$@"; do
          case $value in $t) matched=0; #break;; esac
          echo "matched $value with $t"
          ;;
          esac
          done
          return "$matched"



          for var in abdg wabcde aadef abcde 3@3hello hmm3@3hell 'we>we' 'a>dfff' 'dfd>' 'a> de' 'a*> fg'; do
          if check_func "$var" 'aa*' 'abc*' '3@3*' '*>*'; then
          echo "========A match was found for "$var""
          fi
          done


          A simpler version of the function to exactly match your request:



          check_func() :
          matched=1
          value=$1; shift
          for t in "$@"; do
          case $value in $t) matched=0; break;; esac
          done
          return "$matched"






          share|improve this answer





























            1














            For bash:



            Using the properties of regex you can write start with ^ and contain by nothing.



            The list of regexes to check start with aa abc or 3@3 and contains > is:



            ^aa ^abc ^3@3 >


            Make that a properly quoted list and ask bash to use regexes (=~):



            check_func() 
            matched=1
            for test_regex in '^aa' '^abc' '^3@3' '>'; do
            if [[ $var =~ $test_regex ]] ; then
            matched=0
            break
            fi
            done
            return "$matched"


            var='aaIsAMatch'
            if check_func; then
            echo "A match was found"
            fi


            The function has hard-coded the list of matches and the name of the var.



            Giving the list of regex in an array variable and the value to test on the first argument:



            check_func() 
            local matched; matched=1
            for t in "$test_regex[@]"; do
            [[ $1 =~ $t ]] && matched=0; break;
            done
            return "$matched"



            test_regex=('^aa' '^abc' '^3@3' '>')

            if check_func 'aaIsAMatch'; then
            echo "A match was found"
            fi


            The function could be further improved to use the name of a variable (instead of a value) as the first argument.



            posix



            As there is no regex in posix shells and the only way to test is a case statement, we must use a case statement. Sadly, for older shells ([no extended globs available][1]) we must loop to make all tests. And, the globs need to be:



            'aa*' 'abc*' '3@3*' '*>*'


            An script example that tests several input strings against several globs:



            check_func() :
            matched=1
            value=$1; shift
            for t in "$@"; do
            case $value in $t) matched=0; #break;; esac
            echo "matched $value with $t"
            ;;
            esac
            done
            return "$matched"



            for var in abdg wabcde aadef abcde 3@3hello hmm3@3hell 'we>we' 'a>dfff' 'dfd>' 'a> de' 'a*> fg'; do
            if check_func "$var" 'aa*' 'abc*' '3@3*' '*>*'; then
            echo "========A match was found for "$var""
            fi
            done


            A simpler version of the function to exactly match your request:



            check_func() :
            matched=1
            value=$1; shift
            for t in "$@"; do
            case $value in $t) matched=0; break;; esac
            done
            return "$matched"






            share|improve this answer



























              1












              1








              1







              For bash:



              Using the properties of regex you can write start with ^ and contain by nothing.



              The list of regexes to check start with aa abc or 3@3 and contains > is:



              ^aa ^abc ^3@3 >


              Make that a properly quoted list and ask bash to use regexes (=~):



              check_func() 
              matched=1
              for test_regex in '^aa' '^abc' '^3@3' '>'; do
              if [[ $var =~ $test_regex ]] ; then
              matched=0
              break
              fi
              done
              return "$matched"


              var='aaIsAMatch'
              if check_func; then
              echo "A match was found"
              fi


              The function has hard-coded the list of matches and the name of the var.



              Giving the list of regex in an array variable and the value to test on the first argument:



              check_func() 
              local matched; matched=1
              for t in "$test_regex[@]"; do
              [[ $1 =~ $t ]] && matched=0; break;
              done
              return "$matched"



              test_regex=('^aa' '^abc' '^3@3' '>')

              if check_func 'aaIsAMatch'; then
              echo "A match was found"
              fi


              The function could be further improved to use the name of a variable (instead of a value) as the first argument.



              posix



              As there is no regex in posix shells and the only way to test is a case statement, we must use a case statement. Sadly, for older shells ([no extended globs available][1]) we must loop to make all tests. And, the globs need to be:



              'aa*' 'abc*' '3@3*' '*>*'


              An script example that tests several input strings against several globs:



              check_func() :
              matched=1
              value=$1; shift
              for t in "$@"; do
              case $value in $t) matched=0; #break;; esac
              echo "matched $value with $t"
              ;;
              esac
              done
              return "$matched"



              for var in abdg wabcde aadef abcde 3@3hello hmm3@3hell 'we>we' 'a>dfff' 'dfd>' 'a> de' 'a*> fg'; do
              if check_func "$var" 'aa*' 'abc*' '3@3*' '*>*'; then
              echo "========A match was found for "$var""
              fi
              done


              A simpler version of the function to exactly match your request:



              check_func() :
              matched=1
              value=$1; shift
              for t in "$@"; do
              case $value in $t) matched=0; break;; esac
              done
              return "$matched"






              share|improve this answer















              For bash:



              Using the properties of regex you can write start with ^ and contain by nothing.



              The list of regexes to check start with aa abc or 3@3 and contains > is:



              ^aa ^abc ^3@3 >


              Make that a properly quoted list and ask bash to use regexes (=~):



              check_func() 
              matched=1
              for test_regex in '^aa' '^abc' '^3@3' '>'; do
              if [[ $var =~ $test_regex ]] ; then
              matched=0
              break
              fi
              done
              return "$matched"


              var='aaIsAMatch'
              if check_func; then
              echo "A match was found"
              fi


              The function has hard-coded the list of matches and the name of the var.



              Giving the list of regex in an array variable and the value to test on the first argument:



              check_func() 
              local matched; matched=1
              for t in "$test_regex[@]"; do
              [[ $1 =~ $t ]] && matched=0; break;
              done
              return "$matched"



              test_regex=('^aa' '^abc' '^3@3' '>')

              if check_func 'aaIsAMatch'; then
              echo "A match was found"
              fi


              The function could be further improved to use the name of a variable (instead of a value) as the first argument.



              posix



              As there is no regex in posix shells and the only way to test is a case statement, we must use a case statement. Sadly, for older shells ([no extended globs available][1]) we must loop to make all tests. And, the globs need to be:



              'aa*' 'abc*' '3@3*' '*>*'


              An script example that tests several input strings against several globs:



              check_func() :
              matched=1
              value=$1; shift
              for t in "$@"; do
              case $value in $t) matched=0; #break;; esac
              echo "matched $value with $t"
              ;;
              esac
              done
              return "$matched"



              for var in abdg wabcde aadef abcde 3@3hello hmm3@3hell 'we>we' 'a>dfff' 'dfd>' 'a> de' 'a*> fg'; do
              if check_func "$var" 'aa*' 'abc*' '3@3*' '*>*'; then
              echo "========A match was found for "$var""
              fi
              done


              A simpler version of the function to exactly match your request:



              check_func() :
              matched=1
              value=$1; shift
              for t in "$@"; do
              case $value in $t) matched=0; break;; esac
              done
              return "$matched"







              share|improve this answer














              share|improve this answer



              share|improve this answer








              edited 7 hours ago

























              answered 8 hours ago









              IsaacIsaac

              13k12159




              13k12159





















                  1














                  Revised based on clarification to the question:
                  This is less elegant (and much less flexible),
                  but more compact than the other answers,



                  check_func() abc* 


                  This returns true for aardvark, abcdef, 3@3com.com and 12>5
                  And, of course, also aard>vark, abc<def>ghi and 3@3>3.






                  share|improve this answer





























                    1














                    Revised based on clarification to the question:
                    This is less elegant (and much less flexible),
                    but more compact than the other answers,



                    check_func() abc* 


                    This returns true for aardvark, abcdef, 3@3com.com and 12>5
                    And, of course, also aard>vark, abc<def>ghi and 3@3>3.






                    share|improve this answer



























                      1












                      1








                      1







                      Revised based on clarification to the question:
                      This is less elegant (and much less flexible),
                      but more compact than the other answers,



                      check_func() abc* 


                      This returns true for aardvark, abcdef, 3@3com.com and 12>5
                      And, of course, also aard>vark, abc<def>ghi and 3@3>3.






                      share|improve this answer















                      Revised based on clarification to the question:
                      This is less elegant (and much less flexible),
                      but more compact than the other answers,



                      check_func() abc* 


                      This returns true for aardvark, abcdef, 3@3com.com and 12>5
                      And, of course, also aard>vark, abc<def>ghi and 3@3>3.







                      share|improve this answer














                      share|improve this answer



                      share|improve this answer








                      edited 5 hours ago

























                      answered 8 hours ago









                      G-ManG-Man

                      14.6k94175




                      14.6k94175





















                          0














                          Here's what the case statement does: take the second parameter to the function ($2). If it matches the pattern "$1"*, i.e. the first argument to the function followed by anything, then execute true and end the case statement. true does nothing and returns the status 0. Otherwise, if it matches *, i.e. anything, execute false and end the case statement. false does nothing and returns the status 1. Thus the case statement has the status 0 if the second parameter starts with the first parameter and 1 otherwise. Since this is the last (and only) statement in the function, the function returns 0 if the second parameter starts with the first parameter and 1 otherwise.



                          Conditional statements such as if in the shell consider a statement to be true if it returns 0 and false otherwise. Hence if beginswith "$var" "string"; then echo yes; else echo no; fi prints yes if the value of var starts with string and no otherwise.



                          There are several alternative ways to write this function. For example the author could have used return 0 or return 1 instead of true and false, since they are the last statement in the function. The way the function was written makes it possible to use its body directly without wrapping it in a function, by just changing references to the function parameters ($1 and $2) to whatever strings you want to work with.



                          To allow multiple prefixes, iterate over them in a loop. As soon as you've found a matching prefix, return from the function, with a true status (0). If none of the prefixes match, return a false status (conventionally 1).



                          # begins_with STRING PREFIX1 PREFIX2...
                          # Test if STRING starts with any of PREFIX1, PREFIX2, ...
                          begins_with ()
                          string=$1
                          shift
                          for prefix in "$@"; do
                          case "$string" in
                          "$prefix"*) return 0;;
                          esac
                          done
                          return 1


                          if begins_with "$var" 'aa' 'abc' '3@3'; then
                          echo "The value starts with one of the permitted prefixes"
                          fi


                          To test for a suffix, use the pattern *"$suffix" instead of "$prefix"*. To test for a substring, use *"$substring"*. Note that the double quotes are necessary here, otherwise the variable would be interpreted as a pattern. For example:



                          suffix='?'
                          case "$var" in
                          *"$suffix") echo "The value of var ends with a question mark";;
                          esac
                          case "$var" in
                          *$suffix) echo "The value of var is not empty";;
                          esac





                          share|improve this answer



























                            0














                            Here's what the case statement does: take the second parameter to the function ($2). If it matches the pattern "$1"*, i.e. the first argument to the function followed by anything, then execute true and end the case statement. true does nothing and returns the status 0. Otherwise, if it matches *, i.e. anything, execute false and end the case statement. false does nothing and returns the status 1. Thus the case statement has the status 0 if the second parameter starts with the first parameter and 1 otherwise. Since this is the last (and only) statement in the function, the function returns 0 if the second parameter starts with the first parameter and 1 otherwise.



                            Conditional statements such as if in the shell consider a statement to be true if it returns 0 and false otherwise. Hence if beginswith "$var" "string"; then echo yes; else echo no; fi prints yes if the value of var starts with string and no otherwise.



                            There are several alternative ways to write this function. For example the author could have used return 0 or return 1 instead of true and false, since they are the last statement in the function. The way the function was written makes it possible to use its body directly without wrapping it in a function, by just changing references to the function parameters ($1 and $2) to whatever strings you want to work with.



                            To allow multiple prefixes, iterate over them in a loop. As soon as you've found a matching prefix, return from the function, with a true status (0). If none of the prefixes match, return a false status (conventionally 1).



                            # begins_with STRING PREFIX1 PREFIX2...
                            # Test if STRING starts with any of PREFIX1, PREFIX2, ...
                            begins_with ()
                            string=$1
                            shift
                            for prefix in "$@"; do
                            case "$string" in
                            "$prefix"*) return 0;;
                            esac
                            done
                            return 1


                            if begins_with "$var" 'aa' 'abc' '3@3'; then
                            echo "The value starts with one of the permitted prefixes"
                            fi


                            To test for a suffix, use the pattern *"$suffix" instead of "$prefix"*. To test for a substring, use *"$substring"*. Note that the double quotes are necessary here, otherwise the variable would be interpreted as a pattern. For example:



                            suffix='?'
                            case "$var" in
                            *"$suffix") echo "The value of var ends with a question mark";;
                            esac
                            case "$var" in
                            *$suffix) echo "The value of var is not empty";;
                            esac





                            share|improve this answer

























                              0












                              0








                              0







                              Here's what the case statement does: take the second parameter to the function ($2). If it matches the pattern "$1"*, i.e. the first argument to the function followed by anything, then execute true and end the case statement. true does nothing and returns the status 0. Otherwise, if it matches *, i.e. anything, execute false and end the case statement. false does nothing and returns the status 1. Thus the case statement has the status 0 if the second parameter starts with the first parameter and 1 otherwise. Since this is the last (and only) statement in the function, the function returns 0 if the second parameter starts with the first parameter and 1 otherwise.



                              Conditional statements such as if in the shell consider a statement to be true if it returns 0 and false otherwise. Hence if beginswith "$var" "string"; then echo yes; else echo no; fi prints yes if the value of var starts with string and no otherwise.



                              There are several alternative ways to write this function. For example the author could have used return 0 or return 1 instead of true and false, since they are the last statement in the function. The way the function was written makes it possible to use its body directly without wrapping it in a function, by just changing references to the function parameters ($1 and $2) to whatever strings you want to work with.



                              To allow multiple prefixes, iterate over them in a loop. As soon as you've found a matching prefix, return from the function, with a true status (0). If none of the prefixes match, return a false status (conventionally 1).



                              # begins_with STRING PREFIX1 PREFIX2...
                              # Test if STRING starts with any of PREFIX1, PREFIX2, ...
                              begins_with ()
                              string=$1
                              shift
                              for prefix in "$@"; do
                              case "$string" in
                              "$prefix"*) return 0;;
                              esac
                              done
                              return 1


                              if begins_with "$var" 'aa' 'abc' '3@3'; then
                              echo "The value starts with one of the permitted prefixes"
                              fi


                              To test for a suffix, use the pattern *"$suffix" instead of "$prefix"*. To test for a substring, use *"$substring"*. Note that the double quotes are necessary here, otherwise the variable would be interpreted as a pattern. For example:



                              suffix='?'
                              case "$var" in
                              *"$suffix") echo "The value of var ends with a question mark";;
                              esac
                              case "$var" in
                              *$suffix) echo "The value of var is not empty";;
                              esac





                              share|improve this answer













                              Here's what the case statement does: take the second parameter to the function ($2). If it matches the pattern "$1"*, i.e. the first argument to the function followed by anything, then execute true and end the case statement. true does nothing and returns the status 0. Otherwise, if it matches *, i.e. anything, execute false and end the case statement. false does nothing and returns the status 1. Thus the case statement has the status 0 if the second parameter starts with the first parameter and 1 otherwise. Since this is the last (and only) statement in the function, the function returns 0 if the second parameter starts with the first parameter and 1 otherwise.



                              Conditional statements such as if in the shell consider a statement to be true if it returns 0 and false otherwise. Hence if beginswith "$var" "string"; then echo yes; else echo no; fi prints yes if the value of var starts with string and no otherwise.



                              There are several alternative ways to write this function. For example the author could have used return 0 or return 1 instead of true and false, since they are the last statement in the function. The way the function was written makes it possible to use its body directly without wrapping it in a function, by just changing references to the function parameters ($1 and $2) to whatever strings you want to work with.



                              To allow multiple prefixes, iterate over them in a loop. As soon as you've found a matching prefix, return from the function, with a true status (0). If none of the prefixes match, return a false status (conventionally 1).



                              # begins_with STRING PREFIX1 PREFIX2...
                              # Test if STRING starts with any of PREFIX1, PREFIX2, ...
                              begins_with ()
                              string=$1
                              shift
                              for prefix in "$@"; do
                              case "$string" in
                              "$prefix"*) return 0;;
                              esac
                              done
                              return 1


                              if begins_with "$var" 'aa' 'abc' '3@3'; then
                              echo "The value starts with one of the permitted prefixes"
                              fi


                              To test for a suffix, use the pattern *"$suffix" instead of "$prefix"*. To test for a substring, use *"$substring"*. Note that the double quotes are necessary here, otherwise the variable would be interpreted as a pattern. For example:



                              suffix='?'
                              case "$var" in
                              *"$suffix") echo "The value of var ends with a question mark";;
                              esac
                              case "$var" in
                              *$suffix) echo "The value of var is not empty";;
                              esac






                              share|improve this answer












                              share|improve this answer



                              share|improve this answer










                              answered 8 hours ago









                              GillesGilles

                              557k13411431654




                              557k13411431654





















                                  0














                                  For anything involving text manipulation, Python is going to be far easier to write in:



                                  check_func()
                                  python -c "from sys import exit; exit(0) if any(['$1'.startswith(x) for x in ('aa', 'abc', '3@3')]) and '>' in '$1' else exit(1)"



                                  I use it for all my bash scripts now even the kind that call lots of other programs and reads their results. It's just so much easier and doesn't suffer from weird errors like Bash seems too.






                                  share|improve this answer





























                                    0














                                    For anything involving text manipulation, Python is going to be far easier to write in:



                                    check_func()
                                    python -c "from sys import exit; exit(0) if any(['$1'.startswith(x) for x in ('aa', 'abc', '3@3')]) and '>' in '$1' else exit(1)"



                                    I use it for all my bash scripts now even the kind that call lots of other programs and reads their results. It's just so much easier and doesn't suffer from weird errors like Bash seems too.






                                    share|improve this answer



























                                      0












                                      0








                                      0







                                      For anything involving text manipulation, Python is going to be far easier to write in:



                                      check_func()
                                      python -c "from sys import exit; exit(0) if any(['$1'.startswith(x) for x in ('aa', 'abc', '3@3')]) and '>' in '$1' else exit(1)"



                                      I use it for all my bash scripts now even the kind that call lots of other programs and reads their results. It's just so much easier and doesn't suffer from weird errors like Bash seems too.






                                      share|improve this answer















                                      For anything involving text manipulation, Python is going to be far easier to write in:



                                      check_func()
                                      python -c "from sys import exit; exit(0) if any(['$1'.startswith(x) for x in ('aa', 'abc', '3@3')]) and '>' in '$1' else exit(1)"



                                      I use it for all my bash scripts now even the kind that call lots of other programs and reads their results. It's just so much easier and doesn't suffer from weird errors like Bash seems too.







                                      share|improve this answer














                                      share|improve this answer



                                      share|improve this answer








                                      edited 5 hours ago

























                                      answered 5 hours ago









                                      BenjaminBenjamin

                                      765




                                      765




















                                          No Imaginatition is a new contributor. Be nice, and check out our Code of Conduct.









                                          draft saved

                                          draft discarded


















                                          No Imaginatition is a new contributor. Be nice, and check out our Code of Conduct.












                                          No Imaginatition is a new contributor. Be nice, and check out our Code of Conduct.











                                          No Imaginatition is a new contributor. Be nice, and check out our Code of Conduct.














                                          Thanks for contributing an answer to Unix & Linux Stack Exchange!


                                          • 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%2funix.stackexchange.com%2fquestions%2f523625%2fwrite-a-function-that-checks-if-a-string-starts-with-or-contains-something%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

                                          19. јануар Садржај Догађаји Рођења Смрти Празници и дани сећања Види још Референце Мени за навигацијуу

                                          Israel Cuprins Etimologie | Istorie | Geografie | Politică | Demografie | Educație | Economie | Cultură | Note explicative | Note bibliografice | Bibliografie | Legături externe | Meniu de navigaresite web oficialfacebooktweeterGoogle+Instagramcanal YouTubeInstagramtextmodificaremodificarewww.technion.ac.ilnew.huji.ac.ilwww.weizmann.ac.ilwww1.biu.ac.ilenglish.tau.ac.ilwww.haifa.ac.ilin.bgu.ac.ilwww.openu.ac.ilwww.ariel.ac.ilCIA FactbookHarta Israelului"Negotiating Jerusalem," Palestine–Israel JournalThe Schizoid Nature of Modern Hebrew: A Slavic Language in Search of a Semitic Past„Arabic in Israel: an official language and a cultural bridge”„Latest Population Statistics for Israel”„Israel Population”„Tables”„Report for Selected Countries and Subjects”Human Development Report 2016: Human Development for Everyone„Distribution of family income - Gini index”The World FactbookJerusalem Law„Israel”„Israel”„Zionist Leaders: David Ben-Gurion 1886–1973”„The status of Jerusalem”„Analysis: Kadima's big plans”„Israel's Hard-Learned Lessons”„The Legacy of Undefined Borders, Tel Aviv Notes No. 40, 5 iunie 2002”„Israel Journal: A Land Without Borders”„Population”„Israel closes decade with population of 7.5 million”Time Series-DataBank„Selected Statistics on Jerusalem Day 2007 (Hebrew)”Golan belongs to Syria, Druze protestGlobal Survey 2006: Middle East Progress Amid Global Gains in FreedomWHO: Life expectancy in Israel among highest in the worldInternational Monetary Fund, World Economic Outlook Database, April 2011: Nominal GDP list of countries. Data for the year 2010.„Israel's accession to the OECD”Popular Opinion„On the Move”Hosea 12:5„Walking the Bible Timeline”„Palestine: History”„Return to Zion”An invention called 'the Jewish people' – Haaretz – Israel NewsoriginalJewish and Non-Jewish Population of Palestine-Israel (1517–2004)ImmigrationJewishvirtuallibrary.orgChapter One: The Heralders of Zionism„The birth of modern Israel: A scrap of paper that changed history”„League of Nations: The Mandate for Palestine, 24 iulie 1922”The Population of Palestine Prior to 1948originalBackground Paper No. 47 (ST/DPI/SER.A/47)History: Foreign DominationTwo Hundred and Seventh Plenary Meeting„Israel (Labor Zionism)”Population, by Religion and Population GroupThe Suez CrisisAdolf EichmannJustice Ministry Reply to Amnesty International Report„The Interregnum”Israel Ministry of Foreign Affairs – The Palestinian National Covenant- July 1968Research on terrorism: trends, achievements & failuresThe Routledge Atlas of the Arab–Israeli conflict: The Complete History of the Struggle and the Efforts to Resolve It"George Habash, Palestinian Terrorism Tactician, Dies at 82."„1973: Arab states attack Israeli forces”Agranat Commission„Has Israel Annexed East Jerusalem?”original„After 4 Years, Intifada Still Smolders”From the End of the Cold War to 2001originalThe Oslo Accords, 1993Israel-PLO Recognition – Exchange of Letters between PM Rabin and Chairman Arafat – Sept 9- 1993Foundation for Middle East PeaceSources of Population Growth: Total Israeli Population and Settler Population, 1991–2003original„Israel marks Rabin assassination”The Wye River Memorandumoriginal„West Bank barrier route disputed, Israeli missile kills 2”"Permanent Ceasefire to Be Based on Creation Of Buffer Zone Free of Armed Personnel Other than UN, Lebanese Forces"„Hezbollah kills 8 soldiers, kidnaps two in offensive on northern border”„Olmert confirms peace talks with Syria”„Battleground Gaza: Israeli ground forces invade the strip”„IDF begins Gaza troop withdrawal, hours after ending 3-week offensive”„THE LAND: Geography and Climate”„Area of districts, sub-districts, natural regions and lakes”„Israel - Geography”„Makhteshim Country”Israel and the Palestinian Territories„Makhtesh Ramon”„The Living Dead Sea”„Temperatures reach record high in Pakistan”„Climate Extremes In Israel”Israel in figures„Deuteronom”„JNF: 240 million trees planted since 1901”„Vegetation of Israel and Neighboring Countries”Environmental Law in Israel„Executive branch”„Israel's election process explained”„The Electoral System in Israel”„Constitution for Israel”„All 120 incoming Knesset members”„Statul ISRAEL”„The Judiciary: The Court System”„Israel's high court unique in region”„Israel and the International Criminal Court: A Legal Battlefield”„Localities and population, by population group, district, sub-district and natural region”„Israel: Districts, Major Cities, Urban Localities & Metropolitan Areas”„Israel-Egypt Relations: Background & Overview of Peace Treaty”„Solana to Haaretz: New Rules of War Needed for Age of Terror”„Israel's Announcement Regarding Settlements”„United Nations Security Council Resolution 497”„Security Council resolution 478 (1980) on the status of Jerusalem”„Arabs will ask U.N. to seek razing of Israeli wall”„Olmert: Willing to trade land for peace”„Mapping Peace between Syria and Israel”„Egypt: Israel must accept the land-for-peace formula”„Israel: Age structure from 2005 to 2015”„Global, regional, and national disability-adjusted life years (DALYs) for 306 diseases and injuries and healthy life expectancy (HALE) for 188 countries, 1990–2013: quantifying the epidemiological transition”10.1016/S0140-6736(15)61340-X„World Health Statistics 2014”„Life expectancy for Israeli men world's 4th highest”„Family Structure and Well-Being Across Israel's Diverse Population”„Fertility among Jewish and Muslim Women in Israel, by Level of Religiosity, 1979-2009”„Israel leaders in birth rate, but poverty major challenge”„Ethnic Groups”„Israel's population: Over 8.5 million”„Israel - Ethnic groups”„Jews, by country of origin and age”„Minority Communities in Israel: Background & Overview”„Israel”„Language in Israel”„Selected Data from the 2011 Social Survey on Mastery of the Hebrew Language and Usage of Languages”„Religions”„5 facts about Israeli Druze, a unique religious and ethnic group”„Israël”Israel Country Study Guide„Haredi city in Negev – blessing or curse?”„New town Harish harbors hopes of being more than another Pleasantville”„List of localities, in alphabetical order”„Muncitorii români, doriți în Israel”„Prietenia româno-israeliană la nevoie se cunoaște”„The Higher Education System in Israel”„Middle East”„Academic Ranking of World Universities 2016”„Israel”„Israel”„Jewish Nobel Prize Winners”„All Nobel Prizes in Literature”„All Nobel Peace Prizes”„All Prizes in Economic Sciences”„All Nobel Prizes in Chemistry”„List of Fields Medallists”„Sakharov Prize”„Țara care și-a sfidat "destinul" și se bate umăr la umăr cu Silicon Valley”„Apple's R&D center in Israel grew to about 800 employees”„Tim Cook: Apple's Herzliya R&D center second-largest in world”„Lecții de economie de la Israel”„Land use”Israel Investment and Business GuideA Country Study: IsraelCentral Bureau of StatisticsFlorin Diaconu, „Kadima: Flexibilitate și pragmatism, dar nici un compromis în chestiuni vitale", în Revista Institutului Diplomatic Român, anul I, numărul I, semestrul I, 2006, pp. 71-72Florin Diaconu, „Likud: Dreapta israeliană constant opusă retrocedării teritoriilor cureite prin luptă în 1967", în Revista Institutului Diplomatic Român, anul I, numărul I, semestrul I, 2006, pp. 73-74MassadaIsraelul a crescut in 50 de ani cât alte state intr-un mileniuIsrael Government PortalIsraelIsraelIsraelmmmmmXX451232cb118646298(data)4027808-634110000 0004 0372 0767n7900328503691455-bb46-37e3-91d2-cb064a35ffcc1003570400564274ge1294033523775214929302638955X146498911146498911

                                          Кастелфранко ди Сопра Становништво Референце Спољашње везе Мени за навигацију43°37′18″ СГШ; 11°33′32″ ИГД / 43.62156° СГШ; 11.55885° ИГД / 43.62156; 11.5588543°37′18″ СГШ; 11°33′32″ ИГД / 43.62156° СГШ; 11.55885° ИГД / 43.62156; 11.558853179688„The GeoNames geographical database”„Istituto Nazionale di Statistica”проширитиууWorldCat156923403n850174324558639-1cb14643287r(подаци)