I want to know the exact content of MACHINE_FEATURES.
The first thing I tried was:
bitbake -e <image> > bitbake.txt
inspecting the file I find rows like these:
MACHINE_EXTRA_RDEPENDS=""
#
# $MACHINE_EXTRA_RRECOMMENDS [10 operations]
# _append /local/STM32MP15-Ecosystem-v1.1.0/Distribution-Package/openstlinux-4.19-thud-mp1-19-10-09/layers/meta-st/meta-st-stm32mp/conf/machine/include/st-machine-features-stm32mp.inc:54
# " ${GPU_IMAGE_INSTALL} ${OPTEE_IMAGE_INSTALL} ${ALSA_ADDONS_INSTALL} ${BLUETOOTH_IMAGE_INSTALL} "
# set /local/STM32MP15-Ecosystem-v1.1.0/Distribution-Package/openstlinux-4.19-thud-mp1-19-10-09/layers/meta-st/meta-st-stm32mp/conf/machine/include/st-machine-common-stm32mp.inc:38
# " kernel-modules"
# _append /local/STM32MP15-Ecosystem-v1.1.0/Distribution-Package/openstlinux-4.19-thud-mp1-19-10-09/layers/meta-st/meta-st-stm32mp/conf/machine/include/st-machine-common-stm32mp.inc:52
# " ${#bb.utils.contains('MACHINE_FEATURES', 'wifi', 'linux-firmware-bcm43430', '', d)} "
# _append /local/STM32MP15-Ecosystem-v1.1.0/Distribution-Package/openstlinux-4.19-thud-mp1-19-10-09/layers/meta-st/meta-st-stm32mp/conf/machine/include/st-machine-common-stm32mp.inc:53
# " ${#bb.utils.contains('DISTRO_FEATURES','systemd',' wifi-suspend ','',d)} "
The # chars mean they are comment? I mean, the wifi feature is actually added to MACHINE_FEATURES?
How to print out the contents of such a variable?
Just go like bitbake -e <image> | grep "^MACHINE_FEATURES". The commented out lines only hold the evaluation as it happens. For the end result, the only thing that matters is the line which states MACHINE_FEATURES = right at the beginning.
Related
I have a variable set in the following format:
var1="word1 word2 word3"
Is it possible to subset/delete one of the space-delimited word portably? What I want to archive is something like this:
when --ignore option is supplied with the following argument
$ cmd --ignore word1 # case 1
$ cmd --ignore "word1 word2" # case2
I want the var1 changes to have only the following value
"word2 word3" # case1
"word3" #case2
If there is no way to achieve above described, is there a way to improve the efficiency of the following for loop? (The $var1 is in a for loop so my alternative thought to achieve similar was having following code)
# while loop to get argument from options
# argument of `--ignore` is assigned to `$sh_ignore`
for i in $var1
do
# check $i in $sh_ignore instead of other way around
# to avoid unmatch when $sh_ignore has more than 1 word
if ! echo "$sh_ignore" | grep "$i";
then
# normal actions
else
# skipped
fi
done
-------Update-------
After looking around and reading the comment by #chepner I now temporarily using following code (and am looking for improvement):
sh_ignore=''
while :; do
case
# some other option handling
--ignore)
if [ "$2" ]; then
sh_ignore=$2
shift
else
# defined `die` as print err msg + exit 1
die 'ERROR: "--ignore" requires a non-empty option argument.'
fi
;;
# handling if no arg is supplied to --ignore
# handling -- and unknown opt
esac
shift
done
if [ -n "$sh_ignore" ]; then
for d in $sh_ignore
do
var1="$(echo "$var1" | sed -e "s,$d,,")"
done
fi
# for loop with trimmed $var1 as downstream
for i in $var1
do
# normal actions
done
One method might be:
var1=$(echo "$var1" |
tr ' ' '\n' |
grep -Fxv -e "$(echo "$sh_ignore" | tr ' ' '\n')" |
tr '\n' ' ')
Note: this will leave a trailing blank, which can be trimmed off via var1=${var1% }
I have many files in a folder with the format '{galaxyID}-cutout-HSC-I-{#}-pdr2_wide.fits', where {galaxyID} and {#} are different numbers for each file. Here are some examples:
2185-cutout-HSC-I-9330-pdr2_wide.fits
992-cutout-HSC-I-10106-pdr2_wide.fits
2186-cutout-HSC-I-9334-pdr2_wide.fits
I want to change the format of all files in this folder to match the following:
2185_HSC-I.fits
992_HSC-I.fits
2186_HSC-I.fits
namely, I want to take out "cutout", the second number, and "pdr2_wide" from each file name. I would prefer to do this in either Perl or Python. For my Perl script, so far I have the following:
rename [-n];
my #parts=split /-/;
my $this=$parts[0].$parts[1].$parts[2].$parts[3].$parts[4].$parts[5];
$_ = $parts[0]."_".$parts[2]."_".$parts[3];
*fits
which gives me the error message
Not enough arguments for rename at ./rename.sh line 3, near "];" Execution of ./rename.sh aborted due to compilation errors.
I included the [-n] because I want to make sure the changes are what I want before actually doing it; either way, this is in a duplicated directory just for safety.
It looks like you are using the rename you get on Ubuntu (it's not the one that's on my ArchLinux box), but there are other ones out there. But, you've presented it oddly. The brackets around -n shouldn't be there and the ; ends the command.
The syntax, if you are using what I think you are, is this:
% rename -n -e PERL_EXPR file1 file2 ...
The Perl expression is the argument to the -e switch, and can be a simple substitution. Note that this expression is a string that you give to -e, so that probably needs to be quoted:
% rename -n -e 's/-\d+-pdr2_wide//' *.fits
rename(2185-cutout-HSC-I-9330-pdr2_wide.fits, 2185-cutout-HSC-I.fits)
And, instead of doing this in one step, I'd do it in two:
% rename -n -e 's/-cutout-/-/; s/-\d+-pdr2_wide//' *.fits
rename(2185-cutout-HSC-I-9330-pdr2_wide.fits, 2185-HSC-I.fits)
There are other patterns that might make sense. Instead of taking away parts, you can keep parts:
% rename -n -e 's/\A(\d+).*(HSC-I).*/$1-$2.fits/' *.fits
rename(2185-cutout-HSC-I-9330-pdr2_wide.fits, 2185-HSC-I.fits)
I'd be inclined to use named captures so the next poor slob knows what you are doing:
% rename -n -e 's/\A(?<galaxy>\d+).*(HSC-I).*/$+{galaxy}-$2.fits/' *.fits
rename(2185-cutout-HSC-I-9330-pdr2_wide.fits, 2185-HSC-I.fits)
From your description {galaxyID}-cutout-HSC-I-{#}-pdr2_wide.fits, I assume that cutout-HSC-I is fixed.
Here's a script that will do the rename. It takes a list of files on stdin. But, you could adapt to take the output of readdir:
#!/usr/bin/perl
master(#ARGV);
exit(0);
sub master
{
my($oldname);
while ($oldname = <STDIN>) {
chomp($oldname);
# find the file extension/suffix
my($ix) = rindex($oldname,".");
next if ($ix < 0);
# get the suffix
my($suf) = substr($oldname,$ix);
# only take filenames of the expected format
next unless ($oldname =~ /^(\d+)-cutout-(HSC-I)/);
# get the new name
my($newname) = $1 . "_" . $2 . $suf;
printf("OLDNAME: %s NEWNAME: %s\n",$oldname,$newname);
# rename the file
# change to "if (1)" to actually do it
if (0) {
rename($oldname,$newname) or
die("unable to rename '$oldname' to '$newname' -- $!\n");
}
}
}
For your sample input file, here's the program output:
OLDNAME: 2185-cutout-HSC-I-9330-pdr2_wide.fits NEWNAME: 2185_HSC-I.fits
OLDNAME: 992-cutout-HSC-I-10106-pdr2_wide.fits NEWNAME: 992_HSC-I.fits
OLDNAME: 2186-cutout-HSC-I-9334-pdr2_wide.fits NEWNAME: 2186_HSC-I.fits
The above is how I usually do things but here's one with just a regex. It's fairly strict in what it accepts [for safety], but you can adapt as desired:
#!/usr/bin/perl
master(#ARGV);
exit(0);
sub master
{
my($oldname);
while ($oldname = <STDIN>) {
chomp($oldname);
# only take filenames of the expected format
next unless ($oldname =~ /^(\d+)-cutout-(HSC-I)-\d+-pdr2_wide([.].+)$/);
# get the new name
my($newname) = $1 . "_" . $2 . $3;
printf("OLDNAME: %s NEWNAME: %s\n",$oldname,$newname);
# rename the file
# change to "if (1)" to actually do it
if (0) {
rename($oldname,$newname) or
die("unable to rename '$oldname' to '$newname' -- $!\n");
}
}
}
Where can I find the list of reserved variable names for mib2c "language"? I mean the possible variables that are not described here, like ${name}, which evaluates to the OID name that is passed as the argument to mib2c.c.
Are there any other variables like that?
Is there one that carries the name of the .conf file that was passed to the mib2c.
Looking at local/mib2c from net-snmp-5.7.3, the pre-populated variables are populated by the following code:
$outputName = $mibnode->{'label'} if (!defined($outputName));
$outputName =~ s/-/_/g;
$vars{'name'} = $outputName;
$vars{'oid'} = $oid;
$vars{'example_start'} = " /*\n" .
" ***************************************************\n" .
" *** START EXAMPLE CODE ***\n" .
" ***---------------------------------------------***/";
$vars{'example_end'} = " /*\n" .
" ***---------------------------------------------***\n" .
" *** END EXAMPLE CODE ***\n" .
" ***************************************************/";
So, you end up with the following pre-populated variables:
$name is the "output prefix" specified using the -f option (or $mibnode->{'label'}, whatever that is, if the -f option wasn't used), with dashes substituted with underscores.
$oid is the value of mib2c's argument (called "mibNode" in the usage help).
$example_start and $example_end are hard-coded strings.
That's it.
To create $config with the value of the -c argument (or mib2c.conf if the -c option wasn't used), you could alter mib2c to add the following to the assignments shown above:
$vars{config} = $configfile;
Alternatively, I believe the following will also create $config, but the value passed to the -c option will be prepended with a directory name:
#perleval $vars{config} = $configfile; 0#
You could try to obtain the original value with the following (which assumes the original value didn't contain a /);
#perleval $vars{config} = $configfile =~ m{([^/]+)\z}s ? $1 : undef; 0#
Completely untested. I don't know anything about SNMP or mib2c.
I write the follow script, to print one name to the center of my terminal. In the last command, when i use numbers, everything is ok. However, when i use variables x_center and y_center i have a trouble...
#!/bin/sh
`clear`
num_lines=`tput lines`
num_cols=`tput cols`
echo "Enter your Name: "
read name
length_name=`echo $name | wc -c `
length_name=`expr $length_name - 1`
offset=`expr $length_name / 2`
x_center=`expr $num_lines / 2`
y_center=`expr $num_cols / 2`
y_center=`expr $offset + $x_center`
printf "%s = %d, %s = %d\n" "X" "$x_center" "Y" "$y_center"
echo -n "\033[$x_center;$y_centerf" $name
That last line looks as if it was intended to move the cursor:
echo -n "\033[$x_center;$y_centerf" $name
However, it will not because this fragment $y_centerf is not defined, and does not end with the appropriate final character of the control sequence. Rather than do this, one can do
tput cup $x_center $y_center
echo "$name"
The cup means "cursor position", and can be found in the terminfo(5) manual page. CUP likewise can be found in XTerm Control Sequences. The fragment indicated likely was copied from some example using the similar HVP:
CSI Ps ; Ps f
Horizontal and Vertical Position [row;column] (default =
[1,1]) (HVP).
Curly braces could repair it, e.g., ${y_center}f), but (a) HVP is less common than CUP and (b) using hard-coded escapes when tput is already working is problematic.
I have a flat file of records, each 33 lines long. I need to format this file to specs in a template. The template is in DOS format while the source file is in NIX format. The template has specific indenting and spacing which must be adhered to. I've thought of a few options:
BASH with classic nix tools: sed, awk, grep etc...
BASH with template toolkit
Perl eith template toolkit
Perl
These are in order of my familiarity. Here's a sample source record ( NIX format ):
I've reduced the number of newlines to save space ( normally 33 lines ):
JACKSON HOLE SANITARIUM AND REPTILE ZOO
45 GREASY HOLLER LN
JACKSON HOLE, AK 99999
Change Service Requested
BUBBA HOTEP
3 DELIVERANCE RD
MINNEAPOLIS, MN 99998
BUBBA HOTEP 09090909090909
You have a hold available for pickup as of 2012-01-04:
Title: Banjo for Fun and Profit
Author: Williams, Billy Dee
Price: $10
Here's the template ( DOS format -- lines reduced - 66 lines normally):
<%BRANCH-NAME%>
<%BRANCH-ADDR%>
<%BRANCH-CTY%>
<%CUST-NAME%> <%BARCODE%>
You have a hold available for pickup as of <%DATE%>:
Title: <%TITLE%>
Author: <%AUTHOR%>
Price: <%PRICE%>
<%CUST-NAME%>
<%CUST-ADDR%>
<%CUST-CTY%>
end of file
It actually does say "end of file" at the end of each record.
Thoughts? I tend to over-complicate things.
UPDATE2
Figured it out.
My answer is below. Feel free to suggest improvements.
As a starter, here is a hint: Perl HERE-documents (showing just a few substitutions as a demo):
#!/usr/bin/perl
use strict;
use warnings;
my #lines = qw/branchname cust_name barcode bogus whatever/; # (<>);
my ($branchname, $cust_name, $barcode, undef, $whatever) = #lines;
print <<TEMPLATE;
$branchname
<%BRANCH-ADDR%>
<%BRANCH-CTY%>
$cust_name $barcode
You have a hold available for pickup as of <%DATE%>:
Title: <%TITLE%>
Author: <%AUTHOR%>
Price: <%PRICE%>
$cust_name
<%CUST-ADDR%>
<%CUST-CTY%>
end of file
TEMPLATE
Replace the dummy input array with the lines read from the stdin with (<>) if you will. (Use a loop reading n lines and push it to the array if that is more efficient). I just showed the gist, add more variables as required, and skip input lines by specifting undef for the 'capture' variable (as shown).
Now, simply interpolate these variables into your text.
If line-ends are giving you any grief, consider using chomp eg.:
my #lines = (<>); # just read em all...
my #cleaned = map { chomp } #lines;
This is what I am using for this project. Feel free to suggest improvements, or, submit better solutions.
cp $FILE $WORKING # we won't mess with original
NUM_RECORDS=$( grep "^Price:" "$FILE" | wc -l ) # need to know how many records we have
# counting occurences of end of record r
TMP=record.txt # holds single record, used as temp storage in loop below
# Sanity
# Make sure temp storage exists. If not create -- if so, clear it.
[ ! -f $TMP ] && touch $TMP || cat /dev/null >$TMP
# functions
function make_template () {
local _file="$1"
mapfile -t filecontent < "$_file"
_loc_name="${filecontent[0]}"
_loc_strt="${filecontent[1]}"
_loc_city="${filecontent[2]}"
_pat_name="${filecontent[14]}"
_pat_addr="${filecontent[15]}"
_pat_city="${filecontent[16]}"
_barcode=${filecontent[27]:(-14)} # pull barcode from end of string
_date=${filecontent[29]:(-11)} # pull date from end of string
# Test title length - truncate if necessary - 70 chars.
_title=$(grep -E "^Title:" $_file)
MAXLEN=70
[ "${#_title}" -gt "$MAXLEN" ] && _title="${filecontent[31]:0:70}" || :
_auth=$(grep -E "^Author:" $_file)
_price=$(grep -E "^Price:" $_file)
sed "
s#<%BRANCH-NAME%>#${_loc_name}#g
s#<%BRANCH-ADDR%>#${_loc_strt}#g
s#<%BRANCH-CTY%>#${_loc_city}#g
s#<%CUST-NAME%>#${_pat_name}#g
s#<%CUST-ADDR%>#${_pat_addr}#
s#<%CUST-CTY%>#${_pat_city}#
s#<%BARCODE%>#${_barcode}#g
s#<%DATE%>#${_date}#
s#<%TITLE%>#${_title}#
s#<%AUTHOR%>#${_auth}#
s#<%PRICE%>#${_price}#" "$TEMPLATE"
}
####################################
# MAIN
####################################
for((i=1;i<="$NUM_RECORDS";i++))
do
sed -n '1,/^Price:/{p;}' "$WORKING" >"$TMP" # copy first record with end of record
# and copy to temp storage.
sed -i '1,/^Price:/d' "$WORKING" # delete first record using EOR regex.
make_template "$TMP" # send temp file/record to template fu
done
# cleanup
exit 0