I have the following set of files that I want to pass into Bazel using
res=$(git diff --name-only ${COMMIT_HASH}^! | grep '^src/' | uniq | cut -d/ -f2-)
# echo $res
# services/service-a/README.md
# services/service-a/main.go
# ...
bazel query --keep_going 'set(${res})'
But simply trying that results in:
bazel query --keep_going 'set(${res})'
ERROR: Skipping '$': no such target '//:$': target '$' not declared in package '' defined by /Users/aoutadi/code/KeepTruckin/kt/src/BUILD.bazel
ERROR: Skipping '{res': no such target '//:{res': target '{res' not declared in package '' defined by /Users/aoutadi/code/KeepTruckin/kt/src/BUILD.bazel
ERROR: Skipping '}': no such target '//:}': target '}' not declared in package '' defined by /Users/aoutadi/code/KeepTruckin/kt/src/BUILD.bazel
WARNING: --keep_going specified, ignoring errors. Results may be inaccurate
INFO: Empty results
I know that it might be possible to embed my command into the bazel query itself using
bazel query --keep_going 'set($(git diff --name-only ${COMMIT_HASH}^! | grep '^src/' | uniq | cut -d/ -f2-))'
but I would like to avoid this for clarity and instead use $res.
Is this possible?
This is likely because single quotes and double quotes behave differently in bash (assuming you're using bash). Single quotes won't interpolate variables, so try using double quotes:
bazel query --keep_going "set(${res})"
Related
Like in this tutorial I want to see the derivation.
ls /nix/store/*.drv | head -n 1 | nix show-derivation
experimental Nix feature 'nix-command' is disabled; use '--extra-experimental-features nix-command' to override
I retry with the proposed change
ls /nix/store/*.drv | head -n 1 | nix show-derivation --extra-experimental-features nix-command
error: unable to find a flake before encountering filesystem boundary at '/mnt'
nix show-derivation expects its input as command line arguments.
Lacking any inputs, it seems to default to looking up a flake.
This would work, if it wasn't for *.drv producing too many results on my store:
$ nix show-derivation --extra-experimental-features nix-command $(ls /nix/store/*.drv | head -n 1)
bash: /run/current-system/sw/bin/ls: Argument list too long
If you have any .drv files, this works:
$ nix show-derivation --extra-experimental-features nix-command $(find /nix/store -maxdepth 1 -name '*.drv' | head -n 1)
Without any .drv files, $(...) produces no arguments, and that would be another way to get your error message.
For permanent effect add following line to your configuration file "~/.config/nix/nix.conf"
experimental-features = nix-command
Create the conf file if it doesn't exist. You can append other experimental features like flakes etc.
After a lengthy pipe which ends with a grep, I correctly end up with a set of matching absolute paths/files and match string separated by a comma delimiter for each. I want to tag each file with its match string. Complicated also in that the path has spaces but there is none between the delimiter and the preceding and succeeding characters.
I need to be able to deal with an absolute path rather than just the filename within the directory. The match strings are space_free but the filename might not be:
So by way of example, the output of the pipe might look like:
pipe1 | pipe2 |
outputs
/Users/bloggs/Directory One/matched_file.doc,attributes_0001ABC
/Users/bloggs/Directory One/matched_file1.doc,attributeY_2
/Users/bloggs/Directory One/match_file_00x.doc,Attribute_00201
/Users/bloggs/Directory One/matching file 2.doc,attribute_0004
I want to tag each using something which will probably include:
tag --add "$attribute" "$file"
Where attribute refers to the match string eg "Attribute_00201"
Normally I'd just say eg:
tag --add Attribute_00201 /Users/bloggs/Directory\ One/match_file_00x.doc
At this point I am stuck how to parse each line ideally via another pipe and to deal with spaces correctly and execute the tag command. Grateful for any help
So I'm looking for a new pipe, pipe3 to execute or give me the correctly formatted tag command:
pipe1 | pipe2 | pipe3
delivers eg
tag --add Attribute_00201 /Users/bloggs/Directory\ One/match_file_00x.doc
etc
etc
This seems to work
| tee >(cut -f2 -d","| sed 's/^/tag --add /' > temp_out.txt) >(cut -d"," -f1 | sed -e 's/[[:space:]]/\\ /g' > temp_out1.txt) > /dev/null && paste -d' ' temp_out.txt temp_out1.txt > command.sh && chmod +x ./command.sh
I have been using grep to perform recursive search of text inside a directory, i.e.
grep -Hrn "some-text" ./
However, I am running into some troubles when I need to search for pointers or pointers of pointers:
grep -Hrn "double**" ./
> grep: repetition-operator operand invalid
I have made some attempts to go around this, including some I found via Google searches:
grep -Hrn "double[**]" ./
grep -Hrn "double[*][*]" ./
but neither seems to work. Any pointers?
You have to escape * by using \. For example
$ echo "double***" | grep "double\*\*\*"
double***
If you don't escape * it matches the character before the * zero or more times. One * would therefore match e.g. doubleeeee but the second * results in an error since the operand (the character before the *) is not valid since it's again *. That's exactly what the error message tells you.
The version using [] should also work. As mentioned in the comments the issue might be that your variable declarations contain whitespace. The following regex matches these (now using the * operator):
$ echo "double **" | grep "double\s*\*\*"
double **
I usually use fixed strings, like:
grep -FHrn "double**" ./
(the -F)
-F, --fixed-strings
Interpret pattern as a set of fixed strings (i.e., force grep to
behave as fgrep).
https://www.freebsd.org/cgi/man.cgi?query=grep&sektion=&n=1 (also same in rg and GNU grep)
I am running into an issue where I am trying to run the following command:
aws ecs list-task-definitions | grep Foo-Task-Testing | awk -F '/' '{print $2}'
This returns exactly what I am looking for which is just the task definition name.
When running the command in the CLI with just grep i get this:
"arn:aws:ecs:us-east-1:xxxxxxxxxx:task-definition/Foo-Task-Testing-TaskDefinition-OYBZ78KBUI57:1",
When including Awk, I get:
Foo-Task-Testing-TaskDefinition-OYBZ78KBUI57:1"
However, when I try to add this to my Jenkins pipeline:
ecsTaskDefinitionName = Foo-Task-Testing
ecsTaskDefinition = sh(returnStdout: true, script: "aws ecs list-task-definitions | grep $ecsTaskDefinitionName | awk -F '/' '{print \$2}'").trim()
I always get this error message:
/home/jenkins/workspace/foo_test_PR-828#tmp/durable-a5ce4670/script.sh: 1: /home/jenkins/workspace/foo_test_PR-828#tmp/durable-a5ce4670/script.sh: Syntax error: Unterminated quoted string
I have a feeling this has to do with how I am using Awk in Groovy but I can't seem to find enough examples online to confirm this. Can anyone either provide a way of doing this in Groovy w/o using Awk or any experienced Groovy programmers can tell me the correct way of passing Awk?
You can avoid the need for awk with grep -o:
... | grep -o Foo-Task-Testing.*
returns
Foo-Task-Testing-TaskDefinition-OYBZ78KBUI57:1
(-o only returns the match, .* greedily matches everything after)
In my build settings i have define some preprocessor macros
i.e. SANDBOX_ENV=1
I want to use the value of SANDBOX_ENV in my shell script.
I have tried echo "SANDBOX value is = ${GCC_PREPROCESSOR_DEFINITIONS}"
but its giving me all macros values like DEBUG=1 SANDBOX_ENV=1 COCOAPODS=1
I want to use value that is assigned to SANDBOX_ENV
Try this:
#!/bin/bash
GCC_PREPROCESSOR_DEFINITIONS="DEBUG=1 SANDBOX_ENV=1 COCOAPODS=1"
# delete everything before our value ans stuff into TMPVAL
TMPVAL="${GCC_PREPROCESSOR_DEFINITIONS//*SANDBOX_ENV=/}"
# remove everything after our value from TMPVAL and return it
TMPVAL="${TMPVAL// */}"
echo $TMPVAL; #outputs 1
HTH,
bovako
You should be able to parse it easily with awk or something, but here's how I'd do it:
echo $GCC_PREPROCESSOR_DEFINITIONS | grep -Po 'SANDBOX_ENV=\d+' | sed 's/SANDBOX_ENV=//'
In your echo context:
echo "SANDBOX value is $(echo $GCC_PREPROCESSOR_DEFINITIONS | grep -Po 'SANDBOX_ENV=\d+' | sed 's/SANDBOX_ENV=//')"
Basically I piped the contents of GCC_PREPROCESSOR_DEFINITIONS and grepped out the SANDBOX_ENV portion.
grep -P
is to use the Perl regex \d+, because I don't like POSIX. Just a preference. Essentially what
grep -P 'SANDBOX_ENV=\d+'
does is to find the line in the content piped to it that contains the string "SANDBOX_ENV=" and any number of digits succeeding it. If the value might contain alphanumerics you can change the \d for digits to \w for word which encompasses a-zA-Z0-9 and you get:
grep -Po 'SANDBOX_ENV=\w+'
The + just means there must be at least one character of the type specified by the character before it, including all succeeding characters that matches.
the -o (only-matching) in grep -Po is used to isolate the match so that instead of the entire line you just get "SANDBOX_ENV=1".
This output is then piped to the sed command where I do a simple find and replace where I replaced "SANDBOX_ENV=" with "", leaving only the value behind it. There are probably easier ways to do it like with awk, but you'll have to learn that yourself.
If you want to have something self contained within the Build Settings and you don't mind slight indirection, then:
Create User-Defined settings SANDBOX_ENV=1 (or whatever value you want)
In Preprocessor Macros, add SANDBOX_ENV=${SANDBOX_ENV}
In your shell, to test, do
echo ${SANDBOX_ENV}
With the User-Defined Settings, you'll still be able to modify the value for Build Configuration and Architecture. So, for example, you could make the Debug config be SANDBOX_ENV=0 and Release be SANDBOX_ENV=1.
Might be the obvious answer, but have you simply tried:
echo ${SANDBOX_ENV}
If that doesn't work, try using eval:
eval "${GCC_PREPROCESSOR_DEFINITIONS}"
echo ${SANDBOX_ENV}