Tuesday, 15 April 2014

linux - Bash: How do I truncate an array? -


I want to change the value of an array and appreciate any help.

I found that this is an array:

  user = (root isometric okay)  

(this is actually the current user's List) that I want to be able to check that the user is present and if they do not, then to remove the person from the array I tried to evaluate it by putting it in the loop for use:

  $ i user [@]}; "User = (echo (" $ [$ [[[-z $ (grep \ "^ \ $ i \" / etc / shadow)] and \ "s \" / \ $ i // g \ "))" $ Users  

I thought about playing it with something else but I thought I was getting very complicated (I'm not sure I can place an order in an array ) Anyone have an idea on how to do this?

Edit:

How do I enter the variable variable number:

  cnt = 0 for $ i {the user [@]}; Do [-s "$ (grep" ^ $ i "/ etc / shadow)"] & amp; Amp; Users Unset [CNT] ||             

Actually Dennis is also better.

You do not need for the loop. Try it:

  users = (root isometric açau) list = "$ {users [@] /% / |}" # Convert the array to the list, after every user pipe care Add # Find the username between the empty space and the offer from the strip list # Line at the end of the word and the result, create an array out of the results users = ($ (grep -Eo "^ ($ {list //}) \ & gt; / Etc / shadow))  

grep , unraveled, will look like this:

  grep -Eo "^ (root | Isometric | akau |) & gt; "/ etc / shadow  

No comments:

Post a Comment