SED not exiting The Next CEO of Stack OverflowWhy *not* parse `ls` (and what do to instead)?SED not Deleting linesSSH command not exiting properlyInvalid command code with sedExiting a running script with any buttonsed error: “1 not defined in the RE” under OS Xsed command not substituting properlySed not workingSed and BBedit Htmlsed command in script function not working?Programmatically closing pipeline / exiting

Are there languages with no euphemisms?

How can I get through very long and very dry, but also very useful technical documents when learning a new tool?

How can I quit an app using Terminal?

Rotate a column

Where to find order of arguments for default functions

Is the concept of a "numerable" fiber bundle really useful or an empty generalization?

How do I construct this japanese bowl?

Why did we only see the N-1 starfighters in one film?

What does "Its cash flow is deeply negative" mean?

Is it a good idea to use COLUMN AS (left([Another_Column],(4)) instead of LEFT in the select?

Why were Madagascar and New Zealand discovered so late?

Trouble understanding the speech of overseas colleagues

Why didn't Theresa May consult with Parliament before negotiating a deal with the EU?

Why is there a PLL in CPU?

MAZDA 3 2006 (UK) - poor acceleration then takes off at 3250 revs

Return the Closest Prime Number

How to safely derail a train during transit?

What can we do to stop prior company from asking us questions?

Too much space between section and text in a twocolumn document

What happens if you roll doubles 3 times then land on "Go to jail?"

Horror movie/show or scene where a horse creature opens its mouth really wide and devours a man in a stables

How to count occurrences of text in a file?

Can I equip Skullclamp on a creature I am sacrificing?

Science fiction (dystopian) short story set after WWIII



SED not exiting



The Next CEO of Stack OverflowWhy *not* parse `ls` (and what do to instead)?SED not Deleting linesSSH command not exiting properlyInvalid command code with sedExiting a running script with any buttonsed error: “1 not defined in the RE” under OS Xsed command not substituting properlySed not workingSed and BBedit Htmlsed command in script function not working?Programmatically closing pipeline / exiting










0















All,I used following piece of code to list down the contents of a directory in macOS:



#!/bin/bash

echo "hello User"
echo ""
userdir=$1
var_one=$userdir/Library/Application Support/iCloud/Accounts/
if [ -d "$var_one" ]
then
# echo "Direcotry exists"
echo "The AppleID is : "
sed -n '/[*w-]+@([w-]+.)+[w-]+/p'|ls "$var_one"|awk NR==2'print'
echo "~~~~~~~BYE~~~~~~"
break
else
echo "Directory doesn't exists"
echo "The path is $var_one"
fi


If the directory exists then sed command is used along with regex pattern to identify the desired file. The script works fine but doesn't seem to exit. I am new to this and might be missing out important bits & pieces. Any suggestions/codes for further improvement are welcome.










share|improve this question



















  • 1





    there is no input to sed command, sed is waiting on STDIN

    – Archemar
    yesterday











  • Few comments: * You dont need to escape the /. You just need to escape the spaces. * break is only valid in loops.

    – Mike V.D.C.
    yesterday






  • 1





    Also, if you're on macOS, sed is unlikely to know what w is (macOS sed does not know PCRE expressions). Instead, use [[:alnum:]_] (this is a POSIX character class equivalent to w).

    – Kusalananda
    yesterday
















0















All,I used following piece of code to list down the contents of a directory in macOS:



#!/bin/bash

echo "hello User"
echo ""
userdir=$1
var_one=$userdir/Library/Application Support/iCloud/Accounts/
if [ -d "$var_one" ]
then
# echo "Direcotry exists"
echo "The AppleID is : "
sed -n '/[*w-]+@([w-]+.)+[w-]+/p'|ls "$var_one"|awk NR==2'print'
echo "~~~~~~~BYE~~~~~~"
break
else
echo "Directory doesn't exists"
echo "The path is $var_one"
fi


If the directory exists then sed command is used along with regex pattern to identify the desired file. The script works fine but doesn't seem to exit. I am new to this and might be missing out important bits & pieces. Any suggestions/codes for further improvement are welcome.










share|improve this question



















  • 1





    there is no input to sed command, sed is waiting on STDIN

    – Archemar
    yesterday











  • Few comments: * You dont need to escape the /. You just need to escape the spaces. * break is only valid in loops.

    – Mike V.D.C.
    yesterday






  • 1





    Also, if you're on macOS, sed is unlikely to know what w is (macOS sed does not know PCRE expressions). Instead, use [[:alnum:]_] (this is a POSIX character class equivalent to w).

    – Kusalananda
    yesterday














0












0








0








All,I used following piece of code to list down the contents of a directory in macOS:



#!/bin/bash

echo "hello User"
echo ""
userdir=$1
var_one=$userdir/Library/Application Support/iCloud/Accounts/
if [ -d "$var_one" ]
then
# echo "Direcotry exists"
echo "The AppleID is : "
sed -n '/[*w-]+@([w-]+.)+[w-]+/p'|ls "$var_one"|awk NR==2'print'
echo "~~~~~~~BYE~~~~~~"
break
else
echo "Directory doesn't exists"
echo "The path is $var_one"
fi


If the directory exists then sed command is used along with regex pattern to identify the desired file. The script works fine but doesn't seem to exit. I am new to this and might be missing out important bits & pieces. Any suggestions/codes for further improvement are welcome.










share|improve this question
















All,I used following piece of code to list down the contents of a directory in macOS:



#!/bin/bash

echo "hello User"
echo ""
userdir=$1
var_one=$userdir/Library/Application Support/iCloud/Accounts/
if [ -d "$var_one" ]
then
# echo "Direcotry exists"
echo "The AppleID is : "
sed -n '/[*w-]+@([w-]+.)+[w-]+/p'|ls "$var_one"|awk NR==2'print'
echo "~~~~~~~BYE~~~~~~"
break
else
echo "Directory doesn't exists"
echo "The path is $var_one"
fi


If the directory exists then sed command is used along with regex pattern to identify the desired file. The script works fine but doesn't seem to exit. I am new to this and might be missing out important bits & pieces. Any suggestions/codes for further improvement are welcome.







bash shell-script sed osx apple






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited yesterday









h k

94




94










asked yesterday









swasti bhushan debswasti bhushan deb

63




63







  • 1





    there is no input to sed command, sed is waiting on STDIN

    – Archemar
    yesterday











  • Few comments: * You dont need to escape the /. You just need to escape the spaces. * break is only valid in loops.

    – Mike V.D.C.
    yesterday






  • 1





    Also, if you're on macOS, sed is unlikely to know what w is (macOS sed does not know PCRE expressions). Instead, use [[:alnum:]_] (this is a POSIX character class equivalent to w).

    – Kusalananda
    yesterday













  • 1





    there is no input to sed command, sed is waiting on STDIN

    – Archemar
    yesterday











  • Few comments: * You dont need to escape the /. You just need to escape the spaces. * break is only valid in loops.

    – Mike V.D.C.
    yesterday






  • 1





    Also, if you're on macOS, sed is unlikely to know what w is (macOS sed does not know PCRE expressions). Instead, use [[:alnum:]_] (this is a POSIX character class equivalent to w).

    – Kusalananda
    yesterday








1




1





there is no input to sed command, sed is waiting on STDIN

– Archemar
yesterday





there is no input to sed command, sed is waiting on STDIN

– Archemar
yesterday













Few comments: * You dont need to escape the /. You just need to escape the spaces. * break is only valid in loops.

– Mike V.D.C.
yesterday





Few comments: * You dont need to escape the /. You just need to escape the spaces. * break is only valid in loops.

– Mike V.D.C.
yesterday




1




1





Also, if you're on macOS, sed is unlikely to know what w is (macOS sed does not know PCRE expressions). Instead, use [[:alnum:]_] (this is a POSIX character class equivalent to w).

– Kusalananda
yesterday






Also, if you're on macOS, sed is unlikely to know what w is (macOS sed does not know PCRE expressions). Instead, use [[:alnum:]_] (this is a POSIX character class equivalent to w).

– Kusalananda
yesterday











2 Answers
2






active

oldest

votes


















0














Try replacing:



sed -n '/[*w-]+@([w-]+.)+[w-]+/p'|ls "$var_one"|awk NR==2'print'


With something like this:



ls "$var_one" | sed -n '2/[*w-]+@([w-]+.)+[w-]+/p'



See also: Why not parse ls (and what do to instead)?






share|improve this answer






























    0














    There's a few things that could be improved in your script.



    First of all, the sed doesn't do anything because it's not receiving any input. This means that it will just sit there waiting for you to type things on the keyboard into its standard input stream. Additionally, don't use sed or other text editing tools (awk etc.) on filenames. Filenames on Unix systems can, contain newlines, and sed (for example) reads individual lines, which means it would read a filename with an embedded newline as two separate things.



    It's uncommon for filenames to contain newlines, but if a script don't take this into account, a malicious user may possibly use this fact to confuse the script into doing things it wasn't designed to do.



    To find the currently signed in Apple ID, rather than using some heuristic approach, use a tool that can do it for you. With Homebrew, you may install mas:



    brew install mas


    Then,



    mas account


    will give you the currently signed in Apple ID.






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



      );













      draft saved

      draft discarded


















      StackExchange.ready(
      function ()
      StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f508884%2fsed-not-exiting%23new-answer', 'question_page');

      );

      Post as a guest















      Required, but never shown

























      2 Answers
      2






      active

      oldest

      votes








      2 Answers
      2






      active

      oldest

      votes









      active

      oldest

      votes






      active

      oldest

      votes









      0














      Try replacing:



      sed -n '/[*w-]+@([w-]+.)+[w-]+/p'|ls "$var_one"|awk NR==2'print'


      With something like this:



      ls "$var_one" | sed -n '2/[*w-]+@([w-]+.)+[w-]+/p'



      See also: Why not parse ls (and what do to instead)?






      share|improve this answer



























        0














        Try replacing:



        sed -n '/[*w-]+@([w-]+.)+[w-]+/p'|ls "$var_one"|awk NR==2'print'


        With something like this:



        ls "$var_one" | sed -n '2/[*w-]+@([w-]+.)+[w-]+/p'



        See also: Why not parse ls (and what do to instead)?






        share|improve this answer

























          0












          0








          0







          Try replacing:



          sed -n '/[*w-]+@([w-]+.)+[w-]+/p'|ls "$var_one"|awk NR==2'print'


          With something like this:



          ls "$var_one" | sed -n '2/[*w-]+@([w-]+.)+[w-]+/p'



          See also: Why not parse ls (and what do to instead)?






          share|improve this answer













          Try replacing:



          sed -n '/[*w-]+@([w-]+.)+[w-]+/p'|ls "$var_one"|awk NR==2'print'


          With something like this:



          ls "$var_one" | sed -n '2/[*w-]+@([w-]+.)+[w-]+/p'



          See also: Why not parse ls (and what do to instead)?







          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered yesterday









          agcagc

          4,72711138




          4,72711138























              0














              There's a few things that could be improved in your script.



              First of all, the sed doesn't do anything because it's not receiving any input. This means that it will just sit there waiting for you to type things on the keyboard into its standard input stream. Additionally, don't use sed or other text editing tools (awk etc.) on filenames. Filenames on Unix systems can, contain newlines, and sed (for example) reads individual lines, which means it would read a filename with an embedded newline as two separate things.



              It's uncommon for filenames to contain newlines, but if a script don't take this into account, a malicious user may possibly use this fact to confuse the script into doing things it wasn't designed to do.



              To find the currently signed in Apple ID, rather than using some heuristic approach, use a tool that can do it for you. With Homebrew, you may install mas:



              brew install mas


              Then,



              mas account


              will give you the currently signed in Apple ID.






              share|improve this answer



























                0














                There's a few things that could be improved in your script.



                First of all, the sed doesn't do anything because it's not receiving any input. This means that it will just sit there waiting for you to type things on the keyboard into its standard input stream. Additionally, don't use sed or other text editing tools (awk etc.) on filenames. Filenames on Unix systems can, contain newlines, and sed (for example) reads individual lines, which means it would read a filename with an embedded newline as two separate things.



                It's uncommon for filenames to contain newlines, but if a script don't take this into account, a malicious user may possibly use this fact to confuse the script into doing things it wasn't designed to do.



                To find the currently signed in Apple ID, rather than using some heuristic approach, use a tool that can do it for you. With Homebrew, you may install mas:



                brew install mas


                Then,



                mas account


                will give you the currently signed in Apple ID.






                share|improve this answer

























                  0












                  0








                  0







                  There's a few things that could be improved in your script.



                  First of all, the sed doesn't do anything because it's not receiving any input. This means that it will just sit there waiting for you to type things on the keyboard into its standard input stream. Additionally, don't use sed or other text editing tools (awk etc.) on filenames. Filenames on Unix systems can, contain newlines, and sed (for example) reads individual lines, which means it would read a filename with an embedded newline as two separate things.



                  It's uncommon for filenames to contain newlines, but if a script don't take this into account, a malicious user may possibly use this fact to confuse the script into doing things it wasn't designed to do.



                  To find the currently signed in Apple ID, rather than using some heuristic approach, use a tool that can do it for you. With Homebrew, you may install mas:



                  brew install mas


                  Then,



                  mas account


                  will give you the currently signed in Apple ID.






                  share|improve this answer













                  There's a few things that could be improved in your script.



                  First of all, the sed doesn't do anything because it's not receiving any input. This means that it will just sit there waiting for you to type things on the keyboard into its standard input stream. Additionally, don't use sed or other text editing tools (awk etc.) on filenames. Filenames on Unix systems can, contain newlines, and sed (for example) reads individual lines, which means it would read a filename with an embedded newline as two separate things.



                  It's uncommon for filenames to contain newlines, but if a script don't take this into account, a malicious user may possibly use this fact to confuse the script into doing things it wasn't designed to do.



                  To find the currently signed in Apple ID, rather than using some heuristic approach, use a tool that can do it for you. With Homebrew, you may install mas:



                  brew install mas


                  Then,



                  mas account


                  will give you the currently signed in Apple ID.







                  share|improve this answer












                  share|improve this answer



                  share|improve this answer










                  answered yesterday









                  KusalanandaKusalananda

                  138k17258426




                  138k17258426



























                      draft saved

                      draft discarded
















































                      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%2f508884%2fsed-not-exiting%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

                      getting Checkpoint VPN SSL Network Extender working in the command lineHow to connect to CheckPoint VPN on Ubuntu 18.04LTS?Will the Linux ( red-hat ) Open VPNC Client connect to checkpoint or nortel VPN gateways?VPN client for linux machine + support checkpoint gatewayVPN SSL Network Extender in FirefoxLinux Checkpoint SNX tool configuration issuesCheck Point - Connect under Linux - snx + OTPSNX VPN Ububuntu 18.XXUsing Checkpoint VPN SSL Network Extender CLI with certificateVPN with network manager (nm-applet) is not workingWill the Linux ( red-hat ) Open VPNC Client connect to checkpoint or nortel VPN gateways?VPN client for linux machine + support checkpoint gatewayImport VPN config files to NetworkManager from command lineTrouble connecting to VPN using network-manager, while command line worksStart a VPN connection with PPTP protocol on command linestarting a docker service daemon breaks the vpn networkCan't connect to vpn with Network-managerVPN SSL Network Extender in FirefoxUsing Checkpoint VPN SSL Network Extender CLI with certificate

                      Cannot Extend partition with GParted The 2019 Stack Overflow Developer Survey Results Are In Announcing the arrival of Valued Associate #679: Cesar Manara Planned maintenance scheduled April 17/18, 2019 at 00:00UTC (8:00pm US/Eastern) 2019 Community Moderator Election ResultsCan't increase partition size with GParted?GParted doesn't recognize the unallocated space after my current partitionWhat is the best way to add unallocated space located before to Ubuntu 12.04 partition with GParted live?I can't figure out how to extend my Arch home partition into free spaceGparted Linux Mint 18.1 issueTrying to extend but swap partition is showing as Unknown in Gparted, shows proper from fdiskRearrange partitions in gparted to extend a partitionUnable to extend partition even though unallocated space is next to it using GPartedAllocate free space to root partitiongparted: how to merge unallocated space with a partition

                      Marilyn Monroe Ny fiainany manokana | Jereo koa | Meny fitetezanafanitarana azy.