How to assign multiple lines string in Powershell Console - string

When I do enter this in powershell Console
$test=#'
Test
Test'#
And do enter several times, it keeps printing
>>
So I can never finish command.
What to do ?

'# should be first thing in the line or it is considered to be just a part of the string.
$test=#'
Test
Test
'#
This approach also works with #"/"#

As per the section on maximum line length in The PowerShell Best Practices and Style Guide, I would suggest “splatting” the string, like this:
$myStr = ("The family of Dashwood had long been settled in Sussex. Their estate was " +
"large, and their residence was at Norland Park, in the centre of their " +
"property, where, for many generations, they had lived in so respectable " +
"a manner as to engage the general good opinion of their surrounding " +
"acquaintance.")

$test=#'
Test
Test
'#
The important thing to note is that the delimiters include (invisible) carriage returns. There must be one at the end of the starting tag, and one before the closing tag.

Related

Trying to bind a complex file name in a DBI insert place holder, but special characters get mangled

Guys I don't know if this is a bind problem, character set problem or something I haven't considered. Here's the challenge - the file system was written by some cd ripping software but the problem is more generic, I need to be able to insert any legal filename from a Linux OS into a database, this set of titles is just a test case.
I tied to make this as clear as I could:
find(\&process, $_);< populates #fnames with File::Find:name
my $count = scalar #fnames;
print "File count $count\n";
So I use File:Find to fill the array with the file name strings, some are really problematic..
$stm = $dbh_sms->prepare(qq{
INSERT INTO $table (path) VALUES (?)
});
foreach $fname(#fnames){
print "File:$fname\n";
$stm->execute("$fname");
}
Now here's what I see printed, compared to what comes back out of MariaDb, just a few examples showing the problem:
File:/test1/music/THE DOOBIE BROTHERS - BEST OF THE DOOBIES/02 - THE DOOBIE BROTHERS - LONG TRAIN RUNNIN´.mp3
A bunch of these titles have the back ticks, they are problem #1 - here's how they come back out of a select against the table after I populate it:
| /test1/music/THE DOOBIE BROTHERS - BEST OF THE DOOBIES/02 - THE DOOBIE BROTHERS - LONG TRAIN RUNNIN´.mp3
This character is also a problem:
File:/test1/music/Blue Öyster Cult - Workshop Of The Telescopes/01 - Blue Öyster Cult - Don't Fear The Reaper.mp3
From the database:
/test1/music/Blue Ãyster Cult - Workshop Of The Telescopes/01 - Blue Ãyster Cult - Don't Fear The Reaper.mp3
And one more, but far from the last of the problematic strings:
File:/test1/music/Better Than Ezra - Deluxe/03 - Better Than Ezra - Southern Gürl.mp3
Comes out as:
/test1/music/Better Than Ezra - Deluxe/03 - Better Than Ezra - Southern Gürl.mp3
I though this was a character set problem, so I added this to the connect string:
{ RaiseError => 1, mysql_enable_utf8mb4 => 1 }
I've also tried:
$dbh_sms->do('SET NAMES utf8mb4');
Is that a hex C2 being added to the string? (Edit: it's an octal 303, hex c3) I've also tried changing the column to varbinary and still see the same results. Anyone have a clue why this is happening? I'm at a loss....
TIA
Edit - I dumped the table with OD to find out what is actually getting inserted since I was of the belief that with a placeholder, a bind variable would be written without interpolation, basically a binary transfer. To save my eyes, I just did a handful of records concentrating on what I thought was a 'back tick' from the above example, which is an octal 264, AKA "Acute accent - spacing acute".
It is in the table, but preceded by 303 202 and 302, which are a couple of those 'A' characters with the icing on top and a "low quote" character in between. Which contradicts my prior understanding about the utility of place holders and bind variables.
So I am more confused now than before.
I found the problem, it was in the perl character encoding:
$fname = decode("UTF-8", $fname);
was all I needed.

Is there a way to name a directory with slash at the end of it ( ex: nameOfDir/ ) and a directory with 2 words and space between them?

So, basically I have to name several directories with " / " at the end of the name ( ex: nameOfDir/ ) and also to give some others these kind of names :
example 1: The Sun
example 2 : Sth & Sth
example 3 : Sth: 'Sth'
How can I can do this? Whenever I write ' mkdir The Sun' it creates two directories... I am really stuck at this point.
The "/" is a reserved character so you cannot use it as a part of the directory name.
Multiple words and special character like "*", " ", "&" and the like are possible, but I personally recommend against using them as they make names hard to read and easily lead to errors in scripts...

I need to count the number of elements (words) separated by space in R

I have this string for instance,
s
[1] "problem delet detach partit db2 luw v9 7 recent prod environ problem drop detach partit give error db21034e command process sql statement valid command line processor command sql process return sql20285n statement command allow tabl name schemanam tablenam jan1 detach depend asynchron partit detach oper complet reason code 2 sqlstate 55057 research find ibm say need restart instanc solv issu link think seen mani incid describ pleas help issu thank advanc http www 01 ibm com support docview wss uid swg21515721 "
I just need to count the number of words in s..
thanks.
Try this one :
String test="your sample text";
System.out.println("number of words starting on s : "+test.split(" s").length);
split(String regex) - return array of strings split by regex.
in a place of "regex" use " s" (single space before "s") starting of new words in S.

Simulating rolling dice on a dynamic webpage using Bash

I'm currently working on a Bash script that simulates rolling a number of 6-sided dice. This is all taking place within a virtual machine running Debian that's acting as a server. Essentially, my webpage simulates rolling the dice by using the query string to determing the number of dice to be rolled.
For instance, if my URL is http://127.0.0.1/cgi-bin/rolldice.sh?6, I want the webpage to say "You rolled 6 dice" and then, on the next line, print six numbers between 1 and 6 inclusive (that are of course "randomly" generated).
Currently, printing out the "You rolled x dice" header is working fine. However, I'm having trouble with the next part. I'm very new to Bash, so possibly the syntax or something similar is wrong with my loop. Here it is:
for i in {1..$QUERY_STRING }; do
dieRoll = $(( $RANDOM % 6 + 1))
echo $dieRoll
done
Can anyone help me figure out where I'm going wrong? I'll be happy to post the rest of rolldice.sh if needed.
Since .. requires its arguments to be literals, you have to use eval to substitute the variable:
for i in $(eval "echo {1..$QUERY_STRING}"); do
Or if you have the seq command, you can do:
for i in $(seq 1 "$QUERY_STRING")
I recommend the latter -- using eval with input from the user is very dangerous.

Issue with Spaces when Scripting Scala with Process

I am attempting to write an automated script to pngcrush my images (for a website I am working on) and I used scala as a scripting language to write the script to do this. Everything is going well, except that I am having a problem regarding using spaces when I execute the command. I read that you need to use
Seq(a,b,c,d)
where a,b,c,d are strings (that are meant to be separated by a single space) to deal with how Scala/Java handle Strings
The relevant code I have for generating the command to be executed is here. The result variable contains literal path to every filename
for (fileName <- result) {
val string = Seq("pngcrush","brute","-d","\"" + folder.getPath + "/\"","-e",fileName.getName) ++ fileName.getCanonicalPath.replace(" ","\\ ").split(" ").toSeq
I then use
string!
To execute the command. The problem is that the filename for the last section of the command (after the "-e " flag) isn't executed properly because it cannot deal with the directories that have spaces. An example output is shown below
List(pngcrush, brute, -d, "/tmp/d75f7d89-9ed5-4ff9-9181-41ae2fd82da8/", -e, users_off.png, /Users/mdedetrich/3dot/blublocks/src/main/webapp/img/sidebar/my\, group/users_off.png)
And if I run reduceLeft to get the spaces back I obviously get what the proper string is.
pngcrush brute -d "/tmp/1eaca157-0e14-430c-b0a4-677491d70583/" -e users_off.png /Users/mdedetrich/3dot/blublocks/src/main/webapp/img/sidebar/my\ group/users_off.png
Which is what the correct command should be (running the string manually in terminal works fine). However when I attempt to run this through Scala script, I get this
Could not find file: users_off.png
Could not find file: /Users/mdedetrich/3dot/blublocks/src/main/webapp/img/sidebar/my\
Could not find file: group/users_off.png
CPU time decoding 0.000, encoding 0.000, other 0.000, total 0.000 seconds
Any idea what I am doing incorrectly? It seems to be a problem with Scala not parsing strings that have spaces (and splitting it with Seq is not working either). I have tried both using a literal string with spaces and Seq, neither of which seem to work.
Why are you doing this:
replace(" ","\\ ").split(" ")
That is what's splitting the argument, not Process. Why don't you just use the following?
val string = Seq("pngcrush",
"brute",
"-d","\"" + folder.getPath + "/\"",
"-e",fileName.getName,
fileName.getCanonicalPath)

Resources