

InterviewSolution
1. |
Solve : bash concatenate? |
Answer» Hi people, set "str1=Hello" What you want to get is e.g.: "I:\Hello" Code: [Select]set str1=Hello echo %str1% set str3= %~dp0%str1% echo %str3% pause But this has nothing to do with my question, it is the same problem in another scripting language... The only difference is that here it works and in bash scripting it does weird stuff (at my pc at least)#!/bin/bash DIR="$( cd -P "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" PATH="/System/java/" FULL=$DIR$PATH echo $DIR echo $PATH echo $DIR$PATH echo $FULL FULL=${DIR}/System/java/ echo $FULL echo "________________"$DIR$PATH I had to adjust the amount of underscores to see the $DIR$PATH. Hope is helps. I used cygwin btw :-)You just adjusted the number of underscores to the number of signs in DIR/PATh to see them printed next to each other. The point is that I shouldn't neet underscores or whatever "filling signs" to print them next to each other. I have a variable FOO and I want to concatenate it to the variable BAR and store it into a new one FULL. Then when I should print FULL I should see the CONTENTS of FOO at the time of the concatenation and then the contents of BAR at the time of the concatenation. Google says that it should work. All the sites say this: FULL=$FOO$BAR or FULL=$FOO"contents of BAR" or FULL=${FOO}${BAR} EDIT: I found something strange. When I output it to a text file (append > file.txt to the command) it writes the correct output to the file....I think I found it You need to do a dos2unix conversion first. When you MADE your script in (most likely) a windows text editor (like notepad), the text editor puts a cariage return "\r" and another character at the end of each line. You can see these characters in notepad++ by selecting "show all characters" from the "view > non-printable characters" menu. The Bourne again shell does not like these characters. Therfore you need to convert the dos/windows file into a unix file. Cause Unix files have these characters in a different form. What I did: 1. Open cygwin terminal. 2. Type: dos2unix yourfile.sh 3. Hit enter 4. Type: sh yourfile.sh 5. Hit enter No text-overlap in my window Good luckthats nice learning_cmd...your learning very fast....yea i was guessing it was some kind of conversion issue...but didnt know what to do.... nice workThanks that's nice, I didn't think of that immediately! Btw you don't need that dos2unix file, I just used Notepad++ (Edit menu, then Formatting/Format, Unix) Thanks for your time and help you 2 =) If you have a problem, PM me if you want ^^What you said. All CR's gone on the fly Quote from: Bennieboj on January 11, 2012, 09:31:24 AM Thanks that's nice, I didn't think of that immediately!Isn't the point of creating a script so that there is no user intervention?or use tr: Code: [Select]tr -d '\015' < inputfile.txt > result.txt Quote from: Squashman on January 11, 2012, 11:05:20 AM Isn't the point of creating a script so that there is no user intervention? Yes it is, there ain't any user intervention. Why you're quoting my post? I don't see the reference to anything I said and the question. BC: thanks, but I'm not much of a command ninja =) |
|