I'm sorry I do not speak English very well.
I want to use wget to get an excel file with a link :
http://app/sip/rkn/export.php?p1=1&p2=613&p3=01&p4=31&p5=01&p6=2013
but I'm getting an error message :
'p2' is not recognized as an internal or external command,
operable program or batch file.
'p3' is not recognized as an internal or external command,
operable program or batch file.
'p4' is not recognized as an internal or external command,
operable program or batch file.
'p5' is not recognized as an internal or external command,
operable program or batch file.
'p6' is not recognized as an internal or external command,
operable program or batch file.
What can I do to solve this issue? Thanks in advance!
The problem is that the & character is interpreted by the shell, for which it has a special meaning (see here).
Try the following commands in your shell to understand what it does:
$ sleep 2 && echo "2 seconds have passed"
$ sleep 2 && echo "2 seconds have passed" &
Simplified, the syntax runs the specified command before the & in the background, which means the string that comes after the & is interpreted as a new command by the shell. Try this example to understand what happens:
$ wget foo&ls
To overcome the problem, you need to enclose your link in quotes. Double quotes ("") might not be sufficient, because a string enclosed in double quotes is subject to e.g. parameter expansion, so if your link includes something that looks like a shell variable (e.g. $FOO) your link will be mangled.
Enclose it in single quotes instead to make sure wget sees the link "as it is":
$ wget 'http://app/sip/rkn/export.php?p1=1&p2=613&p3=01&p4=31&p5=01&p6=2013'
Your link is broken, if it is a fake link (used in order to do an example), you can try quoting the URL like this:
wget "http://www.example.com/export.php?p1=1&p2=613&p3=01&p4=31&p5=01&p6=2013"
Related
I'm trying to execute npx command containing pipe in regex parameter:
npx depcruise --exclude 'node_modules"|"test' --output-type dot src
But I'm getting error:
'test' is not recognized as an internal or external command, operable program or batch file.
I tried all combinations described here https://octopus.com/blog/powershell-pipe-escaping but none works. Whats is the correct way to escape pipe in such command?
From the windows command line, I can successfully call my script as follows:
python spot_check.py "stop|CHST SQ_ARRIVAL|2.3" "stop|14 ST_ARRIVAL|2.6" "19:06:28" "19:15:00"
However, if I want to use the VS Code debugger, and I pass the same arguments using the args attribute in launch.json
"args": [
"stop|CHST SQ_ARRIVAL|2.3",
"stop|14 ST_ARRIVAL|2.6" ,
"19:06:28",
"19:15:00",
]
Then I get the following error:
(base) c:\Users\1266143\Desktop\stringlines_ml>cd c:\Users\1266143\Desktop\stringlines_ml && cmd /C "set "PYTHONIOENCODING=UTF-8" && set "PYTHONUNBUFFERED=1" && C:\Users\1266143\AppData\Local\Continuum\anaconda3\python.exe c:\Users\1266143\.vscode\extensions\ms-python.python-2019.11.50794\pythonFiles\ptvsd_launcher.py --default --client --host localhost --port 61850 c:\Users\1266143\Desktop\stringlines_ml\spot_check.py "stop|CHST SQ_ARRIVAL|2.3" "stop|14 ST_ARRIVAL|2.6" 19:06:28 19:15:00"
'CHST' is not recognized as an internal or external command,
operable program or batch file.
The part that reads 'CHST' is not recognized as an internal or external command, operable program or batch file. leads me to believe that the | is being interpreted as a redirect, rather than as a character in a string literal argument, and the space following CHST means CHST is being interpreted as a command. But why would these arguments evaluate differently on the command line than in Visual Studio? How can I ensure that these arguments are passed correctly to my command line application when in debug mode?
These aren't the quotes you're looking for
You require quotes around your arguments, as shown when running the script/program directly on the command-line (i.e. "stop|CHST SQ_ARRIVAL|2.3")
But in the JSON, the first set of quotes will get stripped off when the JSON is interpreted, so the string "stop|CHST SQ_ARRIVAL|2.3" in the JSON becomes just stop|CHST SQ_ARRIVAL|2.3 before it's fed to later processes.
Then all the arguments get fed to the Command Line or Python interpreter, which will look something like this (although it will likely be a huge line with a bunch of debugging flags and such):
c:/mypath/myfile stop|CHST SQ_ARRIVAL|2.3 stop|14 ST_ARRIVAL|2.6 19:06:28 19:15:00
The quotes you thought you had around the arguments no longer exist. This means that the parser interprets the vertical bar symbol as the "Pipe" command, which tell it that the first command is done, and it should take the output of that command and "pipe" it to the command that follows.
So, the parser thinks you told it to:
Run the command c:/mypath/myfile stop
Take the output of that command and pipe it to the command CHST SQ_ARRIVAL
Pipe the output of that command to the command 2.3 stop
etc.
Since it can't find the command CHST with the argument SQ_ARRIVAL, it gives you the error message you are seeing.
The fix is in
If you want the quotes to end up being passed along as a part of the argument you'll need to layer them. How to do this depends on how the JSON interpreter will handle multiple sets of quotes (I'm not sure how it does).
A few things to try:
Use triple quotes: """stop|CHST SQ_ARRIVAL|2.3""" - in some parsers, when it sees the first quote it starts a string, but if it sees 2 quotes in a row after that, it makes them into a quote inside the string, rather than ending it. So the first and last quote start and end the string, while the other two pairs of quotes will be condensed into a quote on the outside of your argument
Use a backslash in front of the quotes inside the JSON string: "\"stop|CHST SQ_ARRIVAL|2.3\"" - in many parsers the backslash character is an "escape" character and any character immediately after it is considered a string literal that will be put directly into the string, even if it is normally a special character.
Use single quotes inside the string: "'stop|CHST SQ_ARRIVAL|2.3'" - Since Python can use either single or double quotes as a string, normally any arguments going to a python interpreter with single quotes will also be considered a string. However, I'm not sure the arguments will get that far in this case, they will probably be interpreted by the shell first, which likely will not consider single quotes to be the start of a string (but you never know for sure..).
Which method works may depend on what shell you are using (i.e. Windows command prompt, Powershell, Git Bash, sh, c-sh, etc.). Each of them could handle command line interpretation of strings differently.
If none of these works, knowing the root cause, a further search should turn up the answer. Good luck!
Following the tutorial https://www.gnu.org/software/gawk/manual/gawk.html
i created a cmd file on windows that have a simple awk script
#! /bin/awk -f
BEGIN { print "Don't Panic!" }
However windows doesn't accept the Shebang notation #! and throws me an error:
'#!' is not recognized as an internal or external command, operable
program or batch file.
How can i make the file executable on windows cmd?
The "shebang" (sharp+bang) notation #! is very specifically a Unix/Linux kernel thing; when you use the exec(2) system call to execute a file, there's logic that will look to see if the file is a script and, if so, invoke the specified interpreter on it, instead of just expecting the file itself to be an executable binary. I don't think there's any analogous way to turn a script with an arbitrary interpreter into a directly-executable command on Windows using CMD.
What you can do is pick a file suffix (like .awk), associate that suffix with the awk executable in Explorer, and then use start (or double-clicking) to run awk scripts instead of just typing the bare filename.
But you want to turn an awk script into a command that you can run at the CMD prompt, the most reliable way would be to make a batch (.bat) file that runs awk on the file manually, which looks something like this (assuming the awk script file is in the same folder as the batch file):
#echo off
awk -f "%~dp0filename.awk"
Here's a working example built from your script:
C:\>echo %PATH%
c:\users\mjreed\bin;C:\windows\system32;C:\windows;...
C:\>type \users\mjreed\bin\hello.bat
#echo off
awk -f "%~dp0hello.awk"
C:\>type \users\mjreed\bin\hello.awk
BEGIN { print "Don't Panic!" }
C:\>hello
Don't Panic!
I have a shell script for renaming multiple files in a folder. It works on a rhel host but throws error on a ubuntu14 host.
#!/usr/bin/env bash
SOME_NUMBER=1
rename _file_name.c _file_${SOME_NUMBER}.c path/of/file/*_file_name.c
What changes shall i make in the code to make it work on a ubuntu14 host?
EDIT-1:
For running the code on ubuntu machine i made following change and it works:
rename 's/\_file_name.c$/\_file_1.c/' path/of/file/*_file_name.c
but following doesn't works and i get below error message:
rename 's/\_file_name.c$/\_file_${SOME_NUMBER}.c/' path/of/file/*_file_name.c
ERROR MESSAGE:
Global symbol "$SOME_NUMBER" requires explicit package name at (eval 1) line 1.
Global symbol "$SOME_NUMBER" requires explicit package name at (eval 1) line 1.
Single quotes prevent parameter expansion. Because Perl and shell syntax is similar in this regard, the literal string s/\_file_name.c$/\_file_${SOME_NUMBER}.c/ is passed to Perl, where it tries to expand the undefined variable $SOME_NUMBER.
Use double quotes instead:
rename "s/\_file_name.c$/\_file_${SOME_NUMBER}.c/" path/of/file/*_file_name.c
See Difference between single and double quotes in Bash
Be sure that the value of SOME_NUMBER in your shell script really is just a number, or at least something that, when expanded, produces a valid Perl expression.
Here's a simple bat file:
C:\temp>type a.bat
#echo off
rem try
echo %1
With some difficulty, I am able to pass a&b as parameter to it:
C:\temp>a.bat a&b
a
'b' is not recognized as an internal or external command,
operable program or batch file.
C:\temp>a.bat "a&b"
"a&b"
The paramater has the " character; I can live with it. But I can't figure out how to call it from a cygwin shell:
C:\temp>c:\cygwin\bin\sh
sh-4.1$ ./a.bat a&b
[1] 7760
a
sh: b: command not found
sh-4.1$ ./a.bat a\&b
a
'b' is not recognized as an internal or external command,
operable program or batch file.
[1]+ Done ./a.bat a
sh-4.1$ ./a.bat \"a\&b\"
"\"a
'b\""' is not recognized as an internal or external command,
operable program or batch file.
sh-4.1$ ./a.bat "a\&b"
a\
'b' is not recognized as an internal or external command,
operable program or batch file.
Windows CMD uses ^ to escape most special characters. So you can use that to pass your argument without enclosing quotes.
C:\temp>a.bat a^&b
But the parameter that is received will be a&b. Your batch script will give an error when it attempts to ECHO the value of %1 because the & is not quoted or escaped.
You could safely echo the value if you enclose it in quotes:
echo "%1"
But if you pass the value already enclosed in quotes "a&b", then you get an error again. That is why many batch script use the ~ modifier to remove any existing enclosing quotes (if they exist), and then explicitly add quotes. The following will work if the value of %1 is quoted or unquoted.
echo "%~1"
You still can have problems with something like "a&b"&c, but that is another story :-)
Another option would be to double escape the & in the original command line:
C:\temp>a.bat a^^^&b
Your batch script will recieve a^&b, and then the echo will work.
With regard to Cygwin, I know very little, but I believe I mostly understand tests 1, 2 and 3.
Test 1:
sh-4.1$ ./a.bat a&b
[1] 7760
a
sh: b: command not found
Cygwin is passing a to your batch script and failing to execute command b
Test 2:
sh-4.1$ ./a.bat a\&b
a
'b' is not recognized as an internal or external command, operable program or batch file.
I'm not sure if CMD parses the command line passed from Cygwin before the batch script is executed or not.
If so, then a is getting passed to your batch script, and then CMD.EXE is failing to execute b.
If not, then Cygwin is successfully executing your script and passing a&b, but your ECHO statement is failing as I explained earlier.
One of the following should work with your script, but I'm not sure which:
sh-4.1$ ./a.bat a^\&b
or
sh-4.1$ ./a.bat a^^^\&b
One of the above will pass a^&b and your ECHO should work.
Test 3:
sh-4.1$ ./a.bat \"a\&b\"
"\"a
'b\""' is not recognized as an internal or external command, operable program or batch file.
I have no idea what Cygwin is doing. Somehow it is introducing additional double quotes.
Test 4:
sh-4.1$ ./a.bat "a\&b"
a\
'b' is not recognized as an internal or external command, operable program or batch file.
Cygwin strips the quotes, and the backslash is preserved. Again, either the & is causing problems when CMD.EXE is launching the script, or it is causing problems within the script when you ECHO it.
One of the following should work, passing a^&b to your script. I'm just not sure which one:
sh-4.1$ ./a.bat "a^&b"
or
sh-4.1$ ./a.bat "a^^^&b"
I believe the following will successfully pass "a&b" to your script:
sh-4.1$ ./a.bat '"a&b"'
I also think the following will do the same, though I am not as confident due to the result of Test 3.
sh-4.1$ ./a.bat "\"a&b\""