Find the best deals on HDTVs, UHD TVs, & 4KTVs from your favorite brands. We can provide the delimiter value using IFS and create array from string with spaces, Execute the shell script, and the variable is successfully converted into array and the strings can be iterated separately, tr is a multi purpose tool. Find centralized, trusted content and collaborate around the technologies you use most. Use the tr command to split the string and get the last element in Bash. Next, the last element of a string is extracted from the words array using ${words[-1]}. Check out, 10 Things You Should Avoid in Your ASP.NET Core Controllers. By doing so, we can specify whether to include or exclude empty substrings from the resulting array when splitting a string. from the beginning and then can rely on ; to operate on the resulting string. So you can use this with any other delimiter, although it may not work under all use cases so you should verify this based on your requirement. Here's how to check the number of arguments supplied to your script., Brace expansion in the bash shell is a lesser known but an awesome feature. In Bash, how can I check if a string begins with some value? Method 1: Bash split string into array using parenthesis Method 2: Bash split string into array using read Method 3: Bash split string into array using delimiter Method 4: Bash split string into array using tr Some more examples to convert variable into array in bash Advertisement How to create array from string with spaces? The Bash shellcheck static code analyzer and checker tool recommends in SC2206 to use read -r or mapfile. And, you could also consider creating an intermediate variable to store it. By clicking Post Your Answer, you agree to our terms of service, privacy policy and cookie policy. How can I remove a specific item from an array in JavaScript? If so, some examples pl. rev2023.4.17.43393. Save up to 50% on Women's Accessories when you shop now. Finally, the rev command is used again to reverse the resulting string to obtain the last element. And how to capitalize on that? Finding valid license for project utilizing AGPL 3.0 libraries. By clicking Accept all cookies, you agree Stack Exchange can store cookies on your device and disclose information in accordance with our Cookie Policy. If you set it to some other value, reset it to default whitespace. The input could be coming from any files or other input source. Browse other questions tagged, Where developers & technologists share private knowledge with coworkers, Reach developers & technologists worldwide, Any reason why do you want array? The best answers are voted up and rise to the top, Not the answer you're looking for? How to concatenate string variables in Bash. To learn more, see our tips on writing great answers. MultiValuedMapApache commons ArrayList Collections.sort MultiValuedMap This technique also works with POSIX sh. Sometimes, In a bash script, you want to separate the strings based on delimiter and output multiple strings to save them into variables or for processing. Not the answer you're looking for? Typically energetic Cardi showed off a string of dance moves during the performance, performing her signature twerk multiple times. Subscribe now. This result table contains rows which are the substrings. For example, we can use it to replace the following: The first or all occurrences of the given character in a string. I've had command strings so long that I broke the args up into groups, then assigned the groups in quoted supergoups so that the actual invocation was. Cardi is enjoying an extended Thailand getaway following her Rolling Loud performance. Assuming your variable contains strings separated by comma character instead of white space as we used in above examples Or In bash split string into array? To learn more, see our tips on writing great answers. How to split a string into an array in Bash? Running a hand through her sleek black tresses, the Bodak Yellow hitmaker added inches to her enviable frame with orange platform heels. Do this if you want to get the last element of your current working directory. Can I ask for a refund or credit next year? Why is a "TeX point" slightly larger than an "American point"? Did you try newline on IFS like Here is multiple ways to define multi line string variable in shell. if your variable has string with spaces, put it between double quotes. Interesting the commas have gone when it lists My array[0] despite IFS initialisation, It is possible as I had verified this with. Asking for help, clarification, or responding to other answers. Use space as a delimiter to split the string in bash without the IFS variable and get the last element. Finally, after we run our app, we can inspect the result: The Split(Char[]?, Int32) method in C# is another overloaded version of the Split method that allows us to split a string into substrings based on a specified delimiter character array, but with an additional count parameter that limits the number of substrings returned. If we want to store multiple key-value pairs, we can read input line by line (so no need to use sed to get rid of \n there), and apply same concept I showed above: echo "$greet" > multiline.txt Check the content of the multiline.txt with the cat command. See also Bash Array Reference. In this example, the last element of the string is extracted using the IFS variable, which is set to a colon character ":". Save up to 50% on Trending when you shop now. Great. Shell uses the IFS variable to determine what the field separators are. in an element. If the RemoveEmptyEntries is specified, the method has to perform additional checks to skip over any empty substrings, which can impact performance. Deals and discounts in Tablets you dont want to miss. Can members of the media be held legally responsible for leaking documents they never agreed to keep secret? Use the basename command to split the string and get the last element in Bash. Let's say you have a long string with several words separated by a comma or underscore. bash pattern substitution ("${i//.}") The code assumes that printing "Element:17.0.0" is unintentional. Can anyone help me get my array output to look like this :. Copy bash array to a variable which name is hold by another variable, I don't really understand expansion and quoting on the shell (zsh/bash), Bash to read file and get keyvalue pair split by spaces, Split string into lines, then frame output. That should work, even without backslashes. These are the best Smartphones deals youll find online. EXCLUSIVE: Merseyside ranked top as the area lacking the most sleep, with 74.47 per cent of residents getting less than seven hours of shut-eye each night on average. How are small integers and of certain approximate numbers generated in computations managed in memory? How do I split a string on a delimiter in Bash? Is there a free software for modeling and graphical visualization crystals with defects? You got a robe or something?'. California park launches its first ever 'Pride Nite' where Mickey and Minnie Mouse will be dressed in rainbow costumes - amid Bob Iger's ongoing war with Ron DeSantis in Florida, Texas architects reveal first look at $60M Uvalde school to replace Robb Elementary - which will feature ballistic glass and a symbolic tree to remember the 21 killed, Bizarre moment boy, 13, is rescued from claw machine at North Carolina amusement park after climbing INSIDE to claim a prize, Homeless people who set up camp on the border of Beverly Hills claim they were told to move there by COPS - as locals say they 'fight all hours of the day' and sell drugs, Succession star Nicholas Braun reveals the major TV role he was rejected for: 'I was bummed because I really went for it', Andrew Lloyd Webber admits feeling 'sad' to see The Phantom Of The Opera end its record-breaking Broadway run, Jessie James Decker slams United Airlines for 'humiliating' her pregnant sister Sydney - after flight attendant made her clean up her child's popcorn, Blue Jays pitcher sparks furious traveling etiquette debate after slamming United for making pregnant wife pick up kids' mess, Jack Black makes his solo debut on the Hot 100 Singles charts with his new song Peaches from The Super Mario Bros. Movie, Teen star Piper Rockelle and her mom Tiffany break cover after being sued for $22M by 11 teens featured on channel: Mom 'called herself Madam of YouTube' and 'abused kids', Florida man, 72, has his right leg ripped off below the knee in horrific alligator attack: Two reptiles are shot dead in the water including one with a foot protruding from its mouth, Light the beam again! The */ pattern matches everything up to and includes the last forward slash in the path, and the ## operator removed all of it, leaving only the file name. Sql split string by delimiter and get first element Introduction to the PHP explode () function. How are small integers and of certain approximate numbers generated in computations managed in memory? IFS determines the delimiter on which you want to split the string. Content Discovery initiative 4/13 update: Related questions using a Machine How do I check if a directory exists or not in a Bash shell script? . Is "in fear for one's life" an idiom with limited variations or can you add another noun phrase to it? How to feed pipe-separated content of a shell variable as input to an array variable, sed with here-string fails, but succeeds when echo output piped to sed, Split single string into character array using ONLY bash, bash: convert array into string preserving white spaces. Does contemporary usage of "neithernor" for more than two options originate in the US, Process of finding limits for multivariable functions. Shop our favorite Women's Shoes finds at great prices. How can I check if a program exists from a Bash script? If so, that solves the trouble of properly restoring noglob or IFS settings. Let me show you how to do that with examples. What could a smart phone still do or not do and what would the screen display be if it was sent back in time 30 years to 1993? Use read to read the string into an array. Heres a collection of bash tutorials that will teach you bash shell scripting from the beginning. For example here I have a variable with newline as delimiter. You want to split this string and extract the individual words. For example in this script I have a variable myvar with some strings as element, Here if I want to iterate over individual element of the myvar variable, it is not possible because this will considered as a variable and not an array. Youll learn all the basics of bash scripting. Browse other questions tagged, Where developers & technologists share private knowledge with coworkers, Reach developers & technologists worldwide. The best answers are voted up and rise to the top, Not the answer you're looking for? As a result, the first and second substring is printed without any leading or trailing spaces, and the third substring is printed without any leading space before cherry and any trailing spaces after orange. How can I drop 15 V down to 3.7 V to drive a motor? If employer doesn't have physical address, what is the minimum information I should have from them? Change it to the newline character, as demonstrated below: Bash also has a readarray builtin command, easily searchable in the man page. Tks. The "s" character is used as the substitute command in sed, which is used to search and replace a given pattern in the input text. NOTE: you may wish to save the current IFS so you can restore it afterwards. Making statements based on opinion; back them up with references or personal experience. Can someone please tell me what is written on this score? Should the alternative hypothesis always be the research hypothesis? a continuous series which does not contain a literal . Set IFS (Internal Field Separator). Let us know if you liked the post. How do I parse command line arguments in Bash? Though this requires more code, it can be faster in some cases, especially if the input string is large. Shop our favorite Dog Supplies finds at great prices. Why does Paul interchange the armour in Ephesians 6 and 1 Thessalonians 5? Mike Sipser and Wikipedia seem to disagree on Chomsky's normal form. How to split a string by the third . Deals and discounts in Cookware you dont want to miss. Their mapfile example is complete, but their read example only covers the case of splitting a string by spaces, not newlines, so I learned the complete form of the read command for this purpose from @Toni Dietze's comment here. Method 1: Using IFS variable $IFS (Internal Field Separator) is a special shell variable. @randomir: the command does not accept the string as valid and throws an error while parsing it; (it's the keyword argument passed to, As long as the backslash is the last character of each line, that. The option -a with read command stores the word read into an array in bash. Using Parameter Expansion Use the parameter expansion with regex to remove the special characters from a string in Bash. Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. (A case statement might be simpler, albeit less similar to the OP's code.). :chatgpt Start here for a quick overview of the site, Detailed answers to any questions you might have, Discuss the workings and policies of this site. Can dialogue be put in the same paragraph as action text? Join our 20k+ community of experts and learn about our Top 16 Web API Best Practices. I tried: mycommand -arg1 "very \ long \ string \ which ." but this doesn't work. How to store (and load) a zsh String array to a file? string. Asking for help, clarification, or responding to other answers. How to split a string into an array in Bash? By clicking Accept all cookies, you agree Stack Exchange can store cookies on your device and disclose information in accordance with our Cookie Policy. Stack Exchange network consists of 181 Q&A communities including Stack Overflow, the largest, most trusted online community for developers to learn, share their knowledge, and build their careers. I would prefer to use. omea state finals 2022. employment underemployment and unemployment ielts reading answers with location. When we run the program, we will see the output: When we use the option StringSplitOptions.TrimEntries, it removes any leading or trailing white spaces from the resulting substrings. Site design / logo 2023 Stack Exchange Inc; user contributions licensed under CC BY-SA. To overcome this we convert and split string into array. I use it in many scripts in my eRCaGuy_dotfiles/useful_scripts directory here. I will cover some of them with examples: Normally to define an array we use parenthesis (), so in bash to split string into array we will re-define our variable using open and closed parenthesis, Next execute the shell script. Now your variable can have strings or integers or some special characters, so depending upon your requirement you can choose different methods to convert string into an array. What does Canada immigration officer mean by "I'm not satisfied that you will leave Canada based on your purpose of visit"? Here, the ## operator removes everything up to the string"s last colon(:). Peanut butter and Jelly sandwich - adapted to ingredients from the UK, Put someone on the same pedestal as another, New external SSD acting up, no eject option, What are possible reasons a sound may be continually clicking (low amplitude, no sudden changes in amplitude). Is it considered impolite to mention seeing a new city as an incentive for conference attendance? Taking to the stage for her performance, Cardi certainly caught the eye in a bright gold metallic look. Unexpected results of `texdef` with command defined in "book.cls". Do EU or UK consumers enjoy consumer rights protections from traders that serve them from abroad? That could look like this: #!/usr/bin/env bashset-oerrexit set-opipefail set-onounset Thanks. What screws can be used with Aluminum windows? The default value of IFS is white space. Deals and discounts in Pet Parents you dont want to miss. Welcome back! you can change IFS just for one line using IFS=$'\n' names=(${names}) on line 9. The one and only resource you'll ever need to learn APIs: Want to kick start your web development in C#? How to insert an item into an array at a specific index (JavaScript), Sort array of objects by string property value. We also specify the RemoveEmptyEntries option to exclude any empty entries or whitespaces from the resulting substrings array. How can I make inferences about individuals from aggregated data? 2. In addition, the regular expression . What is more efficient or recommended for reading output of a command into variables in Bash? IFS='<delimiter>' IFS is an internal variable that determines how Bash recognizes word boundaries. Why hasn't the Attorney General investigated Justice Thomas? A secondary problem is that the IFS=$'\n' assignment is permanent, and may cause trouble later; it's best to set IFS back to normal as soon as possible after changing it like this. Deals and discounts in Cookbooks you dont want to miss. Ask Question Asked 7 years, 2 months ago. The NF variable is automatically set by awk and contains the number of fields in the current record. Find the best deals on Women's Handbags & Wallets from your favorite brands. Deals and discounts in Womens Active Shoes & Sneakers you dont want to miss. Lets explore [], Your email address will not be published. To download the source code for this article, you can visit our, Wanna join Code Maze Team, help us produce more awesome .NET/C# content and. Share Improve this answer Follow edited Jul 23, 2013 at 2:26 for/while 0 .. ${#string}-1bash=~printf eval{..} bash NLS ASCIIsed . Here, the -n option, followed by the number 1, is used to print only the last line. Sorry, something went wrong. @kan , actually this is a small portion of a large script, the original script uses the index for other purposes, that's why I want to keep the array. You are showing just step with converting a string into array. How to convert a string to lower case in Bash, How to concatenate string variables in Bash, Check existence of input argument in a Bash shell script. I suspect the OP didn't expect the indentation to be part of the resulting argument. Note that <<< is called a "herestring". Is it considered impolite to mention seeing a new city as an incentive for conference attendance? Perform a quick search across GoLinuxCloud. Wowzers! Splitting the string into words tells the shell to use a : as the delimiter. It's the same as joining line 8 and line 9. set -- $var'' # split+glob for i do printf 'item: <%s>\n' "$i" done or: Method 2: Split string using tr command in Bash. Thats the reason why I prefer the first method to split string in bash. Now you can easily take all values in a array by ${array[@]}. Find the best deals on More Pets Supplies from your favorite brands. Use the IFS (Internal Field Separator) variable with a delimiter to split the string and get the last element in Bash. I want to split it by . Alternative ways to code something like a table within a table? What to do during Summer? Reading a space-delimited string into an array in Bash. In Bash, the sed command performs text transformations on the input text. Here, It is used to reference the last field in a record, which is the last element of the string we want to extract. $* joins the arguments of the join function, with the IFS, that is temporarily set to be empty in a subshell, for the delimiter. Then, this variable is passed to the basename command using the $() syntax to execute the command and capture its output. split the string into an array, delimited by semicolons, remove the prefix elementwise and store the result in a string, delimited by the first character of IFS, globally add back whitespace behind the delimiters. This allows us to extract the last element of a string split by tr. "The last element of the Path is: $filename", Use IFS Command with a colon as Delimeter. Start here for a quick overview of the site, Detailed answers to any questions you might have, Discuss the workings and policies of this site. How do I assign the output of a command into an array? Browse other questions tagged, Where developers & technologists share private knowledge with coworkers, Reach developers & technologists worldwide. In a related post, you may also want to read about string comparison in bash. Practical Extraction and Reporting Language, The philosopher who believes in Web Assembly, Improving the copy in the close modal and post notices - 2023 edition, New blog post from our CEO Prashanth: Community is the future of AI, Split string into array and print each element on a new line with commandline, Extract variables from text file into array with Bash, Perl and Regex, Index range of array doesn't allow you to iterate over a new line in bash. If the input path ends with a trailing slash, the basename command returns an empty string as output. In what context did Garak (ST:DS9) speak of a lie between two truths? The Split(Char[]?, StringSplitOptions) method in C# allows us to split a string into an array of substrings based on multiple delimiter characters. Let"s see another example where you want to get the last element from the path. Is a copyright claim diminished by an owner's refusal to publish? Use the cut command to split the string and get the last element in Bash. : #!/usr/bin/awk -f NR == 1 { # Get the replacement string from the first line split($0, h, ;); add = h[2] next } { # split the last field by ';' into the array 'a' # n. Site design / logo 2023 Stack Exchange Inc; user contributions licensed under CC BY-SA. Then, it splits the string based on the specified delimiter. Content Discovery initiative 4/13 update: Related questions using a Machine Is there a way to seperate cli --filters arguments onto seperate line like it in bash? man page of tr What information do I need to ensure I kill the same process, not one spawned much later with the same PID? We limit the number of substrings returned to 3 and output each element to the console. Learn more about Stack Overflow the company, and our products. In this example, the "Apple,Banana,Orange" string contained text with commas as separators. Because there could be special characters in the original. We can use the StringSplitOptions enumeration as a parameter for the Split method in C#. UNIX is a registered trademark of The Open Group. We can have a variable with strings separated by some delimiter, so how to split string into array by delimiter? To learn more about using the IndexOf() and Substring() methods in C# strings, check out our informative article on string methods. You've successfully subscribed to Linux Handbook. In this example, the sed command is used with the s (substitute) command to match everything before the last space character in the input string and replace it with nothing. The IFS variable is used with a space delimiter to split the string in the above example. not really, because here the split is nor repeated as in my case, Split a string by multiple delimeters in bash, The philosopher who believes in Web Assembly, Improving the copy in the close modal and post notices - 2023 edition, New blog post from our CEO Prashanth: Community is the future of AI, Awk/sed command to cut on multiple delimiters, How to split a string into an array in bash, Split single string into character array using ONLY bash. Do not sell or share my personal information. What should I do when an employer issues a check and requests my personal banking access details? To extract the last element of this string, the rev command is used to reverse the string. Connect and share knowledge within a single location that is structured and easy to search. Review invitation of an article that overly cites me and the journal. Then, the <<< syntax is used to pass the input string as the input to the read command. See here for where I first learned this: Answer here by @Sanket Parmar: Convert multiline string to array. References: Can members of the media be held legally responsible for leaking documents they never agreed to keep secret? Your email address will not be published. Then, the cut command splits the reversed string at the first comma (,) and selects the first field (-f 1).. Special Variables in Bash Shell Scripting. In my case, its a semi colon. To keep the indentation, I do this. The main problem is this line: IFS=$'\n' StringArray=(${cert_list//$'\n'/ }) The ${cert_list//$'\n'/ } part takes the certificate list, and replaces all newlines in it with spaces, making it all one long line (and since it gets split on newlines, when it's stored as an array it becomes just a single long element).. A secondary problem is that the IFS=$'\n' assignment is permanent, and may . That would also split an empty $var into one empty element. By clicking Post Your Answer, you agree to our terms of service, privacy policy and cookie policy. I've got a file with strings and base64 encoded data over multiple lines, that are sepearated by a comma. By clicking Accept all cookies, you agree Stack Exchange can store cookies on your device and disclose information in accordance with our Cookie Policy. How to check if a string contains a substring in Bash. Does Chain Lightning deal damage to its original target first? What to do during Summer? Linux is a registered trademark of Linus Torvalds. In old versions of bash you had to quote variables after <<<. Traders that serve bash split multi line string into array from abroad more about Stack Overflow the company and! Split the string terms of service, privacy policy and cookie policy overly cites me and the journal continuous which. Or underscore string comparison in Bash set by awk and contains the number of returned. Note: you may wish to save the current IFS so you can easily take all values a. As Delimeter is `` in fear for one line using IFS= $ '\n ' (! Point '' slightly larger than an `` American point '' slightly larger than an `` American ''! In Cookware you dont want to split the string and get the last in. Address, what is written on this score string '' s see another example you. An intermediate bash split multi line string into array to determine what the Field separators are, that the! Include or exclude empty substrings from the words array using $ { i//. } '' omea state finals employment... Would also split an empty string as output results of ` texdef ` command. When splitting a bash split multi line string into array into array by delimiter and get the last element Bash... Api best Practices with some value you shop now wish to save the current IFS so you can it! With some value `` book.cls '' signature twerk multiple times beginning and then can on! Why has n't the Attorney General investigated Justice Thomas any files or other input source be faster some. Showed off a string on a delimiter in Bash without the IFS $. @ ] } zsh string array to a file with strings separated by some delimiter, how. Freebsd and other Un * x-like operating systems to print only the last element in Bash continuous series does. To include or exclude empty substrings from the resulting string to obtain the last.... In SC2206 to use a: as the input string is extracted from the resulting string to.! ] } immigration officer mean by `` I 'm not satisfied that you will leave Canada based the! To search learn more, see our tips on writing great answers a single location that is structured easy! That will teach you Bash shell scripting from the resulting string $ ( ) syntax to execute the command capture! Number of substrings returned to 3 and output each element to the string and get the last in... ` texdef ` with command defined in `` book.cls '' the media be held legally for! My personal banking access details pass the input to the basename command using the $ ( ) to! Private knowledge with coworkers, Reach developers & technologists share private knowledge with coworkers, Reach &! To extract the last element in Bash, Process of finding limits for functions. Ifs command with a space delimiter to split the string into array recommends in SC2206 to read. Ever need to learn APIs: want to get the last element of current... First element Introduction to the basename command bash split multi line string into array an empty $ var into one element! This result table bash split multi line string into array rows which are the substrings API best Practices a space-delimited string array... Overflow the company, and our products energetic Cardi showed off a string into an array with strings separated some... To check if a string into array by delimiter and get the last element of media... Ifs= $ '\n ' names= ( $ { array [ @ ] } got a file with strings separated some... Split an empty $ var into one empty element mean by `` I 'm not satisfied that you will Canada!, that are sepearated by a comma showing just step with converting a on..., privacy policy and cookie policy, Reach developers & technologists worldwide deal damage to its original target?! Array to a file the given character in a related Post, you wish... Indentation to be part of the media be held legally responsible for leaking documents never..., we can have a variable with a delimiter to split string by delimiter ask for a or. You could also consider creating an intermediate variable to determine what the Field separators.... Assumes that printing `` Element:17.0.0 '' is unintentional works with POSIX sh favorite Dog Supplies finds great. On HDTVs, UHD TVs, & 4KTVs from your favorite brands path... Continuous series which does not contain a literal here by @ Sanket Parmar: convert multiline string to obtain last. Command line arguments in Bash help me get my array output to look this... Signature twerk multiple times finally, the rev command is used with space. Canada based on opinion ; back them up with references or personal experience take all values in array! Rely on ; to operate on the specified delimiter: want to split the string in Bash, <..., what is more efficient or recommended for reading output of a string into an array a... And our products why I prefer the first or all occurrences of the Group. Convert multiline string to obtain the last element of your current working directory has to perform additional checks to over. As Delimeter & # x27 ; s say you have a long string with spaces, put it between quotes... Have from them limit the number of substrings returned to 3 and output each element the... Which are the substrings reading a space-delimited string into words tells the shell to use:! An employer issues a check and requests my personal banking access details! /usr/bin/env bashset-oerrexit set-opipefail set-onounset.! Printing `` Element:17.0.0 '' is unintentional just step with converting a string a! $ IFS ( Internal Field Separator ) is a `` herestring '' string based on the input string as.! Could look like this: Answer here by @ Sanket Parmar: convert string... Email address will not be published serve them from abroad using the $ ( ) function the resulting array. Words [ -1 ] } array output to look like this: here. 50 % on Women 's Accessories when you shop now looking for whether to include or empty... A colon as Delimeter here by @ Sanket Parmar: convert multiline string to the. Text transformations on the specified delimiter normal form slash, the sed command performs text transformations the! If so, we can have a long string with several words separated by some,! Loud performance from them 16 Web API best Practices 10 Things you Avoid. Got a file with strings separated by a comma or underscore fear for one line using IFS= '\n... Multiple times on the input could be special characters in the US, of. I remove a specific item from an array in Bash array when splitting string... Set by awk and contains the number of substrings returned to 3 output... Beginning and then can rely on ; to operate on the resulting string to obtain the last.. The performance, performing her signature twerk multiple times an idiom with limited variations can. Need to learn more, see our tips on writing great answers splitting a string to 3 and output element... File with strings separated by some delimiter, so how to split the string and get last! Did you try newline on IFS like here is multiple ways to code like. To quote variables after < < input path ends with a trailing slash, the rev command is used a... Responsible for leaking documents they never agreed to keep secret and contains the number,. 3.7 V to drive a motor in old versions of Bash you had to quote variables after