Error manually regenerating .proto files - bash

I am trying to implement the stickynote application in this tutorial https://cloud.google.com/solutions/mobile/mobile-compute-engine-grpc
However, when i try to manually regenerate my .proto files i get the following error message
-bash: !ProtoCompiler/protoc: event not found
Here is the command i am trying to run on the command line
../Pods/!ProtoCompiler/protoc —plugin=protoc-gen-grpc=../Pods/!ProtoCompiler-gRPCPlugin/grpc_objective_c_plugin —objc_out=. —grpc_out=. -I . -I ../Pods/!ProtoCompiler *.proto
Not sure what the error could be

! is a special character in bash used for History Expansion Event Designation
Single quote your argument strings including it or escape using \
../Pods/\!ProtoCompiler/protoc —plugin=protoc-gen-grpc='../Pods/!ProtoCompiler-gRPCPlugin/grpc_objective_c_plugin' —objc_out=. —grpc_out=. -I . -I '../Pods/!ProtoCompiler' *.proto
Even better, rename the directory/binaries so that they don't have ! in them.

Related

How to pass several files with iterative names to an executable function in a bash script?

I have an executable file that takes input .h5 files and returns and output .h5 file. I produces several input files with iterative names and I would like to pass them to the executable in a for loop.
I think there is a problem with for definition, I tried different syntaxes for for none of which worked.
for input_data_ in Dataset/*.h5;
do
for ((n=1; n<=10, n++))
do
./myexecutable -i "$input_data_" -o "output/$(basename "$input_data_" .h)_out.h5"
done
done
I get this error: "arithmetic expression required"
The input file names: input_data_1.h5, input_data_2.h5 ...
I pass the files with -i to the executable and -o returns the output file. The files are located in a folder called Dataset.
There is a syntax error in the for loop.
for ((n=1; n<=10, n++))
You have used , instead of ;. That is why you are getting an "arithmetic expression required" error.
Changing it to for ((n=1; n<=10; n++)) will fix the error.

Dockerfile: COPY / ADD with space character in path (Windows)

In Windows 10 (cmd) I'm trying to copy a file from a subfolder containing a space character in its name.
First I tried to use quotation marks:
FROM jfloff/alpine-python:2.7
COPY "Folder 1/File.txt" "Dir 1"
Error message:
failed to process "\"Folder": unexpected end of statement while looking for matching double-quote
"JSON" format (skipped the first line):
COPY ["Folder 1/File.txt" "Dir 1"]
Error message:
failed to process "[\"Folder": unexpected end of statement while looking for matching double-quote
Trying to escape with a single backslash:
COPY "Folder\ 1/File.txt" "Dir\ 1"
Error message:
failed to process "\"Folder\\": unexpected end of statement while looking for matching double-quote
Trying to escape with a double backslash:
COPY "Folder\\ 1/File.txt" "Dir\\ 1"
Error message:
failed to process "\"Folder\\\\": unexpected end of statement while looking for matching double-quote
Also tried a suggestion to use %20 instead of space:
COPY ["Folder%201/File.txt" "Dir%201"]
Error message:
COPY failed: no source File
Escape character replacement:
# escape=`
COPY "Folder` 1/File.txt" "Dir 1"
Error message:
failed to process "\"Folder`": unexpected end of statement while looking for matching double-quote
The same, but without quotes:
#escape=`
COPY Folder` 1/File.txt Dir` 1
Error message:
COPY failed: stat /var/lib/docker/tmp/docker-builder082039614/Folder: no such file or directory
Method with packing / unpacking using a tar archive (I'm not happy with that idea).
It should be possible, shouldn't it?
Maybe you can use ARG to help you, like this:
Dockerfile:
FROM jfloff/alpine-python:2.7
ARG src="Folder 1/File.txt"
ARG target="Dir 1/"
COPY ${src} ${target}
BTW, a / has to be add at the end of Dir 1 if you treat really want to treat it as a folder.
And, JSON format is also ok, just you miss ,, it should be:
FROM jfloff/alpine-python:2.7
COPY ["Folder 1/File.txt", "Dir 1/"]
Update for your comments:
In official guide, it said:
When copying files or directories that contain special characters (such as [ and ]), you need to escape those paths following the Golang rules to prevent them from being treated as a matching pattern.
So, for your case, it should be:
FROM jfloff/alpine-python:2.7
ARG src="[[]Folder 1]/__SLIM_TEMPLATE.mm"
ARG target="[Folder 1]/"
COPY ${src} ${target}
Or:
FROM jfloff/alpine-python:2.7
COPY ["[[]Folder 1]/__SLIM_TEMPLATE.mm", "[Folder 1]/"]
agree it's annoying to get files from docker that have special characters,
had similar experience and after hours of try and errors, I came up with this simple solution that I now use since then.
tar/zip the files and then "docker cp" them easily without having to worry about dozens of []'"..
tar files in your container machine:
#zipped
tar czf myfiles.tar.gz file1.txt dir24 file_xyz
#or unzipped
tar -cvf myfiles.tar file1.txt dir24 file_xyz
Then copy them to local directories in your windows machine.
open cmd in windows
run
# docker cp ABCD_CONTAINER_NAME:PATH/myfiles.tar.gz d:/TARGETDIR/
check if files have been transferred in d:/TARGETDIR/
The solution is the follow:
Docker has updated it's COPY command. So you can use brackets and your filenames can have whitespaces. Read more here (official docs)

bash expression for filenames with two or more date ranges

I am trying to perform operations on a group of log files in unix. The operation is copy.
Let's say I want to copy last weeks log files (January 25th-31st) from the current directory to another directory and those files have names like:
log-20150125, log-20150126, ..., log-20150131
I tried the following in bash:
cp (log-201501)|2[5-9]|3[0-1]*.gz /home/user/bin/Temp
and got an error that says "syntax error near unexpected token log-201501"
I think I'm doing something wrong. What is the expression for capturing two date ranges?
Bash has a lot of syntax, so you can't just throw parentheses and pipes around willy-nilly
shopt -s extglob
cp log-201501#(2[6-9]|3[0-1])*.gz /home/user/bin/Temp
See https://www.gnu.org/software/bash/manual/bashref.html#Pattern-Matching
If that's too incomprehensible, split it up
cp log-2015012[6-9]*.gz log-2015013[0-1]*.gz /home/user/bin/Temp
or brace expansion is nicely readable
cp log-201501{26,27,28,29,30,31}*.gz /home/user/bin/Temp

How to delete files like 'Incoming11781rKD'

I have a programme that is generating files like this "Incoming11781Arp", and there is always Incoming, and there is always 5 numbers, but there are 3 letters/upper-case/lower-case/numbers/special case _ in any way. Like Incoming11781_pi, or Incoming11781rKD.
How can I delete them using a script run from a cron job please? I've tried -
#!/bin/bash
file=~/Mail/Incoming******
rm "$file";
but it failed saying that there was no matching file or directory.
You mustn't double-quote the variable reference for pathname expansion to occur - if you do, the wildcard characters are treated as literals.
Thus:
rm $file
Caveat: ~/Mail/Incoming****** doesn't work the way you think it does and will potentially match more files than intended, as it is equivalent to ~/Mail/Incoming*, meaning that any file that starts with Incoming will match.
To only match files starting with Incoming that are followed by exactly 6 characters, use ~/Mail/Incoming??????, as #Jidder suggests in a comment.
Note that you could make your glob (pattern) even more specific:
file=~/Mail/Incoming[0-9][0-9][0-9][0-9][0-9][[:alpha:]_][[:alpha:]_][[:alpha:]_]
See the bash manual for a description of pathname expansion and pattern syntax: http://www.gnu.org/software/bash/manual/bashref.html#index-pathname-expansion.
You can achieve the same effect with the find command...
$ directory='~/Mail/'
$ file_pattern='Incoming*'
$ find "${directory}" -name "${file_pattern}" -delete
The first two lines define the directory and the file pattern separately, the find command will then proceed to delete any matching files inside that directory.

TeamCity - passing parameter values with whitespace to command line

I'm passing some TeamCity parameters to the command line build step. The problem comes when the parameter value contains spaces, e.g.:
%env.TEAMCITY_BUILDCONF_NAME% ---> My TC Project
Is there a way to replace white spaces with some other character, for example underscore?
%env.TEAMCITY_BUILDCONF_NAME% ---> My_TC_Project
You can typically keep using the white spaces if you wrap the parameter in double quotes:
%program.files.dir% => C:\Program Files (x86)
Executable: dir
Parameters: "%program.files.dir%"
I don't know how to replace spaces with underscore, but I had an issue with whitespaces.
In a TeamCity build step, I was trying to run an sqlcmd as Executable with Parameters
-S %sql_server% -U %sql_username% -P %sql_password%
-i "custom_script.sql" -d "%custom_db%"
-v DealerName="%DealerName%"
where DealerName was "Great Dealer Ltd" but it didn't work with white spaces, even with double quotes.
It fixed the issue by setting it as a Custom Script like
sqlcmd -S %sql_server% -U %sql_username% -P %sql_password%
-i "custom_script.sql" -d "%custom_db%"
-v DealerName="%DealerName%"
and (thanks to my boss suggestion) it worked like charm.
Even if is not the precise answer to your question, it could be useful for similar issues.
String given below worked for me.
%env.TEAMCITY_BUILDCONF_NAME% ---> "My\ TC\ Project"

Resources