How to escape the . when using dot notation commandline arguments - omegaconf

I want to pass in a config like:
foo
blah.bar: blah.bar
another.thing: some.thing
And I want to do this on the commmandline, osmething like:
python my_script.py foo.blah.bar=blah.bar foo.another.thing=some.thing
Obviously, this would give me instead:
foo
blah
bar: blah.bar
another
thing: some.thing
... which is not what I want. How can I escape any periods (.) when using dot notation with omegaconf.OmegaConf.from_cli() ?

Based on the comment here, I think you could do something like:
python my_script.py foo[blah.bar]=blah.bar foo[another.thing]=some.thing
But I've never used omegaconf, so please don't beat me up for guessing :)

This is not supported.
You can file a feature request but it's not going to be high pri. I suggest that you use a different separator in your keys.

Related

Forcing the order of arguments in function generated for a "alias"

When I create an alias like:
alias "myA" "PREFIX $argv SUFFIX"
fish genarates a function with body equivalent to: "PREFIX SUFFIX $argv.
Is there a trick/hack/legitimate way to force the shell so that the call myA 1234 is executed as PREFIX 1234 SUFFIX?
I know how to do that by writing a function. I generate about 15+ of these, on the fly, and the PREFIX, SUFFIX strings keep changing very frequently. So it is not practical to write a function.
Thanks!
Cheers; 'best,
shankar
You seem to have misunderstood what the alias command does. It does define a function. But it does not do the transformation you imply. It only appears to do so because you double-quoted the alias definition. Which means that $argv is interpolated before the function is created. If, as is likely to be the case, $argv is undefined (or the empty array) then "PREFIX $argv SUFFIX" is equivalent to "PREFIX SUFFIX".
To answer your question: No, there is no way to do what you want using the alias command. Honestly, I think alias should never have been added to fish as it isn't needed and simply confuses people migrating from bash where the concept of an "alias" is very different. It's trivial to replace
alias myA "PREFIX $argv SUFFIX"
with
function myA; PREFIX $argv SUFFIX; end

Perl commandline arguments

I have a question about the commandline arguments in Perl. I'm not sure if someone has asked this question before because I'm not sure what to search for.
I'm having an aaplication where I pass some commandline arguments. But I want it to look like this: stepanalyzer --file=glasses.STEP --get=#62296,#3,#883
so I can say --get for example. And how I can pass multiple arguments with the --get
I hope someone is able to help me. Thanks in advance!
The library to use is Getopt::Long
As I said I needed something like --get="616","718"
So with this library you can put: GetOptions('file=s' => \$file, 'get=s' => \#ary);
'file=s'
Means: --file needs a string after it.
'get=s'
Means: The same, where now we can have multiple --get value on the command line and each such option adds its string to #ary. Thus the option as a comma-separated list, requested in the question, is one element in the array and one way to expand this is
#ary = split(/,/, join(',', #ary));
as shown in documentation
But there is also another way to give this: 'get=s#'. What you prefer.

Substitute only one part of a string using perl

I have an array that have some symbols that I want to remove and even thought I find a solution, I will like to know if this is the right way because I'm afraid if I use it with array will remove the character that I might need on future arrays.
Here is an example item on my array:
$string1='22 | logging monitor informational';
so I try the following:
$string1=~ s/\s{6}\|(?=\s{6})//;
So my output is:
22 logging monitor informational
Is the other way that best match "|". I just want to remove the pipe character.
Thanks in advance
"I want to remove just the pipe character."
OK, then do this:
$string1 =~ s/\|//;
This will remove the first pipe character in the string. (You said in another comment that you don't want to remove any additional pipe characters.) If that's not what you want, then I'd suggest telling us exactly what you do want. We can't read minds, you know.
In the mean time, I'd also strongly recommend reading the Perl regular expressions tutorial.

Tcl set command

Quick question... I'm trying the following:
set changedir "cd $JSDIR/"
eval $changedir
..Where $JSDIR is defined already. Running this script gives the error: "set: Variable name must begin with a letter."
What's the fix?
Thanks.
That's not an error message generated by Tcl, because Tcl's variables most definitely do not need to begin with a letter. OK, it tends to be convenient to keep them alphanumeric because the $var shorthand syntax is more restrictive than the general space of variable names, but the set var form can handle virtually anything.
I'm guessing that script is being evaluated by something that isn't Tcl, perhaps bash?
Try to set changedir cd ${JSDIR/} instead
This message can appear when in fact the variable name is entirely correct, and the real problem is that the variable value needs to be quoted. Try instead of: set changedir "cd $JSDIR//"

zsh filename globbling/substitution

I am trying to create my first zsh completion script, in this case for the command netcfg.
Lame as it may sound I have stuck on the first hurdle, disclaimer, I know how to do this crudely, however I seek the "ZSH WAY" to do this.
I need to list the files in /etc/networking but only the files, not the directory component, so I do the following.
echo $(ls /etc/network.d/*(.))
/etc/network.d/ethernet-dhcp /etc/network.d/wireless-wpa-config
What I wanted was:
ethernet-dhcp wireless-wpa-config
So I try (excuse my naivity) :
echo ${(s/*\/)$(ls /etc/network.d/*(.))}
/etc/network.d/ethernet-dhcp /etc/network.d/wireless-wpa-config
It seems that this doesn't work, I'm sure there must be some clever way of doing this by splitting into an array and getting the last part but as I say, I'm complete noob at this.
Any advice gratefully received.
General note: There is no need to use ls to generate the filenames. You might as well use echo some*glob. But if you want to protect the possible embedded newline characters even that is a bad idea. The first example below globs directly into an array to protect embedded newlines. The second one uses printf to generate NUL terminated data to accomplish the same thing without using a variable.
It is easy to do if you are willing to use a variable:
typeset -a entries
entries=(/etc/network.d/*(.)) # generate the list
echo ${entries#/etc/network.d/} # strip the prefix from each one
You can also do it without a variable, but the extra stuff to isolate individual entries is a bit ugly:
# From the inside, to the outside:
# * glob the entries
# * NUL terminate them into a single string
# * split at NUL
# * strip the prefix from each one
echo ${${(0)"$(printf '%s\0' /etc/network.d/*(.))"}#/etc/network.d/}
Or, if you are going to use a subshell anyway (i.e. the command substitution in the previous example), just cd to the directory so it is not part of the glob expansion (plus, you do not have to repeat the directory name):
echo ${(0)"$(cd /etc/network.d && printf '%s\0' *(.))"}
Chris Johnsen's answer is full of useful information about zsh, however it doesn't mention the much simpler solution that works in this particular case:
echo /etc/network.d/*(:t)
This is using the t history modifier as a glob qualifier.
Thanks for your suggestions guys, having done yet more reading of ZSH and coming back to the problem a couple of days later, I think I've got a very terse solution which I would like to share for your benefit.
echo ${$(print /etc/network.d/*(.)):t}
I'm used to seeing basename(1) stripping off directory components; also, you can use echo /etc/network/* to get the file listing without running the external ls program. (Running external programs can slow down completion more than you'd like; I didn't find a zsh-builtin for basename, but that doesn't mean that there isn't one.)
Here's something I hope will help:
haig% for f in /etc/network/* ; do basename $f ; done
if-down.d
if-post-down.d
if-pre-up.d
if-up.d
interfaces