How do I output a scoreboard value or a selector to chat in Bedrock Edition?
You can add this in your .bashrc or .bash_aliases file (or equivalent if your shell is not bash
):
mvcd () {
mv -- "$1" "$2" &&
cd -P -- "$2"
}
Then, restart your shell, then you can use the function like so:
mvcd foo bar
That assumes $2
is not an existing directory as otherwise mv
would move $1
into it as opposed to to it (see the -T
option of GNU mv
to guard against that).
--
marks the end of options. mv "$1" "$2"
would be mv "$option_or_source" "$option_or_argument_to_first_option_or_destination"
. mv -- "$1" "$2"
guarantees that $1
and $2
are not treated as options even if their name starts with -
so it's always treated as mv -- "$source" "$destination"
. Generally, you want to use --
wherever a command is given an arbitrary argument.
-P
(for physical directory traversal) is to prevent the special processing that the cd
builtin of POSIX shells do by default with ..
path components so that it treats the content of $2
the same as mv
did. Without it, in cdmv foo ../bar
, cd
could cd into a different bar
directory from the one mv
renamed foo
as.
If you have set $CDPATH
(or it was in the environment when the shell was started), you would also need to disable it for that one cd
invocation:
mvcd () {
mv -- "$1" "$2" &&
CDPATH= cd -P -- "$2"
}
Some extra corner-case problems remain: -
(and in some shells -2
, +3
) are treated specially even after --
. If you want to rename foo
to -
, use mvcd foo ./-
instead of .mvcd foo -
In ksh93
and bash
:
$ pwd
/tmp
$ mkdir test_dir
$ mv test_dir another_name
$ cd $_
$ pwd
/tmp/another_name
$_
expands to the last argument of the previous command.
As a shell function:
mvcd () {
mv -- "$1" "$2"
cd -P -- "$_"
}
But you may as well use
mvcd () {
mv -- "$1" "$2" &&
cd -P -- "$2"
}
as that would take care of not trying to change directory if the mv
failed.
The double dash is necessary to allow names that start with a dash. The double dash will signal the end of command line options and prevent the name to be interpreted as an option, in those cases.
The -P
with cd
is necessary to make cd
interpret paths in the same way as mv
does ("physically" rather than "logically"). This avoids confusion when the new location is specified with a path that contains ..
and traverses symbolic links.
If you move rather than just rename the directory, one would have to sort out the case where the move does not involve a renaming of the directory:
mv some_dir existing_dir
This would move some_dir
into existing_dir
so one would have to
cd existing_dir/some_dir
to change working directory to the moved directory afterwards.
The following modified shell function takes care of that:
mvcd () {
if [ -d "$2" ]; then
mv -- "$1" "$2" &&
cd -P -- "$2/$1"
else
mv -- "$1" "$2" &&
cd -P -- "$2"
fi
}
or "shorter":
mvcd () {
if [ -d "$2" ] && mv -- "$1" "$2"; then
cd -P -- "$2/$1"
elif mv -- "$1" "$2"; then
cd -P -- "$2"
fi
}
There is no way to combine the mv
and cd
into a truly atomic operation. The mv
has to happen first, then the cd
, no matter how you look at it, even if you wrote it in C. Doing one after the other (while checking the exit status of mv
) is the correct way of doing it.
In your equation, it is not $p$ that is constant, but the component(s) of $p$. This is not a coordinate-invariant statement because the coordinates themselves are changing as you move through the manifold, so whether the components of a vector/tensor field change or not (and how they do) does not give any information on whther or not the actual vector/tensor field changes or not.
In some cases (when your manifold is not endowed with a metric or connection) it is not even possible to separate a "true" rate of change from the "apparent" rate of change.
If it is theoretically possible to do so, that means you have a connection $\nabla$.
In this case the total change of a quantity can be written symbolically as $$ dY=\nabla Y+\delta Y, $$ for some quantity $Y$ where $\nabla Y$ is the "true" or "physically/geometrically" meaningful rate of change and $\delta Y$ is an "apparent" rate of change due to how the coordinate system shifts around.
By analizing the algebraic properties of first-order differential operators, one may realize that $\delta$ must be a zeroth order differential operator, so essentially a pointwise-linear transformation, which we write as $-\Gamma$. So we have $$ \nabla Y=dY+\Gamma Y. $$
I have essentially now introduced the covariant derivative. The point is that it is pretty much always $\nabla$ that we are interested in, the fact that in some coordinate system $p^\beta$ might be constant carries no meaning at all. If you switch to another coordinate system it won't be constant. What you are interested in is the coordinate-invariant derivative which in this case is $$ u^\alpha\nabla_\alpha p^\beta . $$