Get all characters before first instance of another char
Clash Royale CLAN TAG#URR8PPP
up vote
0
down vote
favorite
Say I have
npmv="3.4.5";
what is the simplest way to get all the characters before the first dot? In this case that would be "3"?
bash shell-script
add a comment |Â
up vote
0
down vote
favorite
Say I have
npmv="3.4.5";
what is the simplest way to get all the characters before the first dot? In this case that would be "3"?
bash shell-script
add a comment |Â
up vote
0
down vote
favorite
up vote
0
down vote
favorite
Say I have
npmv="3.4.5";
what is the simplest way to get all the characters before the first dot? In this case that would be "3"?
bash shell-script
Say I have
npmv="3.4.5";
what is the simplest way to get all the characters before the first dot? In this case that would be "3"?
bash shell-script
asked Jun 22 at 7:32
Alexander Mills
1,848929
1,848929
add a comment |Â
add a comment |Â
1 Answer
1
active
oldest
votes
up vote
3
down vote
accepted
npmv="3.4.5"
major=$npmv%%.*
printf 'The major version number is %sn' "$major"
The parameter substitution $variable%%pattern
will remove the longest suffix string matching pattern
from the value of $variable
. The pattern is treated as a filename globbing pattern, not a regular expression. This is a standard parameter substitution that will work in all POSIX shells.
The same thing but with a single %
would remove only the final .5
of the string in the example (the shortest matching suffix pattern). For prefix strings, use #
instead of %
.
See also the section on parameter expansions in the POSIX standard, and your shell's manual.
add a comment |Â
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
3
down vote
accepted
npmv="3.4.5"
major=$npmv%%.*
printf 'The major version number is %sn' "$major"
The parameter substitution $variable%%pattern
will remove the longest suffix string matching pattern
from the value of $variable
. The pattern is treated as a filename globbing pattern, not a regular expression. This is a standard parameter substitution that will work in all POSIX shells.
The same thing but with a single %
would remove only the final .5
of the string in the example (the shortest matching suffix pattern). For prefix strings, use #
instead of %
.
See also the section on parameter expansions in the POSIX standard, and your shell's manual.
add a comment |Â
up vote
3
down vote
accepted
npmv="3.4.5"
major=$npmv%%.*
printf 'The major version number is %sn' "$major"
The parameter substitution $variable%%pattern
will remove the longest suffix string matching pattern
from the value of $variable
. The pattern is treated as a filename globbing pattern, not a regular expression. This is a standard parameter substitution that will work in all POSIX shells.
The same thing but with a single %
would remove only the final .5
of the string in the example (the shortest matching suffix pattern). For prefix strings, use #
instead of %
.
See also the section on parameter expansions in the POSIX standard, and your shell's manual.
add a comment |Â
up vote
3
down vote
accepted
up vote
3
down vote
accepted
npmv="3.4.5"
major=$npmv%%.*
printf 'The major version number is %sn' "$major"
The parameter substitution $variable%%pattern
will remove the longest suffix string matching pattern
from the value of $variable
. The pattern is treated as a filename globbing pattern, not a regular expression. This is a standard parameter substitution that will work in all POSIX shells.
The same thing but with a single %
would remove only the final .5
of the string in the example (the shortest matching suffix pattern). For prefix strings, use #
instead of %
.
See also the section on parameter expansions in the POSIX standard, and your shell's manual.
npmv="3.4.5"
major=$npmv%%.*
printf 'The major version number is %sn' "$major"
The parameter substitution $variable%%pattern
will remove the longest suffix string matching pattern
from the value of $variable
. The pattern is treated as a filename globbing pattern, not a regular expression. This is a standard parameter substitution that will work in all POSIX shells.
The same thing but with a single %
would remove only the final .5
of the string in the example (the shortest matching suffix pattern). For prefix strings, use #
instead of %
.
See also the section on parameter expansions in the POSIX standard, and your shell's manual.
edited Jun 22 at 7:45
answered Jun 22 at 7:39
Kusalananda
101k13199312
101k13199312
add a comment |Â
add a comment |Â
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f451238%2fget-all-characters-before-first-instance-of-another-char%23new-answer', 'question_page');
);
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password