&& Equivalent in Powershell [duplicate] - scripting

This question already has answers here:
What are the PowerShell equivalents of Bash's && and || operators?
(4 answers)
Can I get "&&" or "-and" to work in PowerShell?
(13 answers)
Closed 3 years ago.
In bash I use ./task1.sh && ./task2.sh to run task1, and then run task2 as long as task1 did not return an error code. When I try .\task1.bat && .\task2.bat in Powershell I get the error "The Token && Is not a valid separator in this version."
Is there an equivalent for && in Windows Powershell?

This is the closest I can get:
.\task1.ps1 ; if($?){.\task2.ps1}

I think the closest equivalent would be:
.\task1.bat;if($lastexitcode -eq 0){.\task2.bat}
Also, Powershell has -and which you might want to try, but it is not really the same.

Related

Why there is no output on asking input from user in lua using sublime text [duplicate]

This question already has answers here:
Can't send input to running program in Sublime Text
(5 answers)
Running Code in Sublime text 2 ( Mac OS X )
(1 answer)
Closed 2 years ago.
On initiating this program i got no output, not even the compiler asked me for input
You're supposed to submit text, not images.
That being said: Your script is fine, but Sublime pipes output to the editor, but isn't a full terminal, so doesn't allow input.
#! /usr/bin/env lua
io.write( 'Enter a number : ' )
local a = io.stdin:read('*n')
while a < 200 do
print( 'value of a :', a )
a = a +1
end
You'll have to open an actual terminal, cd into the relevant directory, then run your script.
chmod +x NAME_OF_SCRIPT.lua && ./NAME_OF_SCRIPT.lua
or
lua NAME_OF_SCRIPT.lua

redirect the sql query will add all the files in that directory [duplicate]

This question already has answers here:
Capturing multiple line output into a Bash variable
(7 answers)
When to wrap quotes around a shell variable?
(5 answers)
Closed 5 years ago.
I have shell script as below
query="SELECT * from [myDB.myTable]"
echo $(date +"%Y-%m-%d %H:%M:%S")'|'land'|'Failure'|||'twice'|'$query > test.log
When I run above in some directory in my Unix PC, the test.log shows the result as below
2017-12-13 06:54:03|land|Failure|||twice| SELECT temp1.txt test tmp.log tt.sh from [myDB.myTable]
Actually I wanted query to be redirected as it is in the log file, instead it printed all the file names of that directory.
How can I fix this issue?
The dreaded pathname expansion strikes again! You can attribute that list of filenames to having a * in an unquoted expression.
echo "$(date +'%Y-%m-%d %H:%M:%S')'|'land'|'Failure'|||'twice'|'$query" > "test.log"
# ^ ^
cat "test.log"
> 2017-12-13 06:54:03|land|Failure|||twice| SELECT * from [myDB.myTable]
Use double quotes for your complete echo, the single quotes can be deleted:
echo "$(date +"%Y-%m-%d %H:%M:%S")|land|Failure|||twice|${query}" > test.log
I also have put curly braves in ${query}, that is not a solution for your problem but a good habit for future scripts.

plink - dealing with special charters in password [duplicate]

This question already has answers here:
How can I escape an exclamation mark ! in cmd scripts?
(4 answers)
Closed 3 years ago.
All,
I have a script that is using plink to connect to ~300 routers. I last used it to update a password for an admin account. Short is, password containing ! is failing.
I can SSH to the router with the password containing ! just can't connect using plink. I have tried replacing ! with %21. Tried escaping with ! and ^!. Nothing is working.
Thoughts?
Yea, that was a lot of nonsense to end-up with double ^
So. Escape ! with ^^
Example
plink -pw abc^^!

Why does terminfo disagree with read? [duplicate]

This question already has an answer here:
Why is terminfo[kcuu1] = '\EOA'?
(1 answer)
Closed 5 years ago.
I'm using xterm. If I type infocmp $TERM | grep end, I see that kend=\EOF. However, if I type read, and then the End key, I see that the sequence \E[F is generated. This seems to be a problem with other keys, too.
Surely the values should be identical??
The terminal can be set on a special mode to send keystrokes from the keypad. You can set that mode by running tput smkx and unset it by tput rmkx.

Objective-C: Determine which file has performed an NSLog [duplicate]

This question already has answers here:
How to print out the method name and line number and conditionally disable NSLog?
(13 answers)
Closed 9 years ago.
Say I have 10 different implementation files that are run in an chaotic order, and in each of them I have an NSLog(#"Log");, and when I run the program I will get 10 Log's to my console output, but how can I know which one was logged by which file? I'm searching for something like
`In someFile1.m: Log`
`In someFile3.m: Log`
`In someFile2.m: Log`
`...`
And so on and so forth. Is that possible?
You can use preprocessor macros for that, take a look at this example:
NSLog(#"In %s - %s:%d someObject=%#", __FILE__, __func__, __LINE__, someObject);
Here's what's available:
https://developer.apple.com/library/ios/qa/qa1669/_index.html
You can use __FILE__ macro:
NSLog(#"%s",__FILE__ );
Which outputs filename:
2013-10-16 20:49:17.536 ABC[3637:a0b] /Users/who/where//DeviceViewController.m