Hi all,
I've some strange issues with a shell script for a bundle command. Caused by a "*" (Asterisk) at the end of the line.
Description:
In a folder I've the following files:
test.md AAA-some-text.md
The content of test.md is:
In my bundle script I do a lot with the file. One of the things is that I want to grep the first Header. In this case "# A header with star AAA*".
The shell code is (only the code causing the issue):
#!/bin/bash [[ -f "${TM_SUPPORT_PATH}/lib/bash_init.sh" ]] && . "${TM_SUPPORT_PATH}/lib/bash_init.sh" cd ~/Desktop contenttitle=`grep -m 1 '^#{1}' test.md` echo $contenttitle
When running "grep -m 1 '^#{1}' test.md" in Terminal I get as expected the first header "# A header with star AAA*", but running the script in TextMate I get "# A header with star AAA-some-text.md". Really strange..... there is a replacement of "AAA*" by the filename "AAA-some-text.md" (from the current folder). And even when more files with "AAA" exist, they also come in the result of the script. It seems like there is a listing of the directory performed like "ls AAA*".
Is this a TextMate issue? Or do I something wrong?
Regards, Feek
NB1: when escaping the * in the markdown file (like *), the script is performed right. NB2: when the AAA* text is in the middle of the line (some text on the right), the error persists.
-- View this message in context: http://textmate.1073791.n5.nabble.com/Strange-issues-with-a-shell-script-for... Sent from the textmate users mailing list archive at Nabble.com.
On 9 March 2016 at 21:31, feek feekdiv@gmail.com wrote:
#!/bin/bash [[ -f "${TM_SUPPORT_PATH}/lib/bash_init.sh" ]] && . "${TM_SUPPORT_PATH}/lib/bash_init.sh" cd ~/Desktop contenttitle=`grep -m 1 '^#{1}' test.md` echo $contenttitle
Try adding quotes to the last two lines:
contenttitle="`grep -m 1 …`" echo "$contenttitle"
The last line is subject to filename generation, the second to last may be as well.
HTH, Martin
Hi Martin,
Thnx for the prompt reply!
The quotes solved the problem!
The echo in my example was only for showing for debugging the result, but some I also piped the variable somewhere else via an echo. By quoting the variable the problem is solved!
Really thnx Feek
-- View this message in context: http://textmate.1073791.n5.nabble.com/Strange-issues-with-a-shell-script-for... Sent from the textmate users mailing list archive at Nabble.com.