But what I want is the following.
How can I find the number - in this case the 740 - if I do not know the full specific_filename?
Eg. I know only the 'libvclient_release_x64.so.' part of the filename, but do not know the last '740' part of it, and want to find that unknown part?
Glad that it helped you. You could HIT THANKS button at left most corner of each post if you find any post useful. Off course above will not work for every file name. Since you have provided pattern specific file patterns so I had written as per that file name(s). You may need to change the pattern of file(s) in case your name changes too.
Not sure what you are trying to do, so please try my suggestion into a test environment only.
Also in awk we can't use variable values by using $ , by seeing your command I tried making following command(considering your command works on shell only).
That is difficult to understand or believe, respectively. I touch ed all those files:
ls -la lib*
-rw-rw-r-- 1 user user 0 Aug 21 22:26 libicudata.so
-rw-rw-r-- 1 user user 0 Aug 21 22:26 libicudata.so.54
-rw-rw-r-- 1 user user 0 Aug 21 22:26 libicui18n.so
-rw-rw-r-- 1 user user 0 Aug 21 22:26 libicui18n.so.54
-rw-rw-r-- 1 user user 0 Aug 21 22:26 libicuio.so
-rw-rw-r-- 1 user user 0 Aug 21 22:26 libicuio.so.54
-rw-rw-r-- 1 user user 0 Aug 21 22:26 libicuuc.so
-rw-rw-r-- 1 user user 0 Aug 21 22:26 libicuuc.so.54
-rw-rw-r-- 1 user user 0 Aug 21 22:26 libvclient_release_x64.so
-rw-rw-r-- 1 user user 0 Aug 21 20:36 libvclient_release_x64.so.734
-rw-rw-r-- 1 user user 0 Aug 21 22:26 libvclient_release_x64.so.740
-rw-rw-r-- 1 user user 0 Aug 21 22:26 libvkernel_release_x64.so
-rw-rw-r-- 1 user user 0 Aug 21 22:26 libvkernel_release_x64.so.740
-rw-rw-r-- 1 user user 0 Aug 21 22:26 libvreport_release_x64.so
-rw-rw-r-- 1 user user 0 Aug 21 22:26 libvreport_release_x64.so.740
-rw-rw-r-- 1 user user 0 Aug 21 22:26 libvshared_release_x64.so
-rw-rw-r-- 1 user user 0 Aug 21 22:26 libvshared_release_x64.so.740
and there will be just two files found for the pattern you gave:
There should NOT be that multitude of files listed that you present as the output of echo $number . What be the output of echo libvclient_release_x64.so.* in that environment?
In a test directory on my host, where I created all the files you showed with the touch command.
Again: the error you posted is not reproducible without further information. The reason I insist is that the proposal in post#2 is the most cost / resource effective one and should work perfectly.
Then you get three files:
control.tar.gz
data.tar.xz
debian-binary
Further, you can unpack the data.tar.xz archive and get three directories:
etc/
opt/
usr/
In the opt/VServer/ dir there is among others the
vcomponents/ dir, which contains the files which are in question.
You can see there that in vcomponents/ dir is only one version of libraries, currently it is 740 version. So at a time there is only one number at the end of some filenames.
When my ebuild on Gentoo Linux system unpack the downloaded deb package, it gets the exact dirs and files out there. Naturally, the files and it's versions will change at time.
I hope I explained to you what is the situation. Right?
If it is made very sure that there will be only one numbered file version at a time, then why do you need to find out the sequence number? Create the symlink immediately to the only version that exists.
I presume the dosym command does exactly this: create a symbolic link. If not so, what does it do?
What rdtx1 gave you is a so-called variable expansion in the shell.
This:
Respectively the last part: ${variable_name##*[.]} means: take from the content of variable_name everything after the last ".". To understand how it works try this:
So, rdtx1 showed you a way of isolating the part you are interested in from the full filename. You will still have to provide the full filename first.
But you tried to use an asterisk "*" as part of the filename. This is expanded by the shell not to a single filename but a list of names. Consider the following:
# ls -l
total 0
-rw-rw-r-- 1 bakunin users 0 Aug 22 15:04 afile.123
-rw-rw-r-- 1 bakunin users 0 Aug 22 15:04 bfile.456
-rw-rw-r-- 1 bakunin users 0 Aug 22 15:04 cfile.789
# var=afile.123 # storing a fixed name in the variable
# echo ${var##*[.]}
123
# var=* # storing the asterisk
# echo $var
afile.123 bfile.456 cfile.789
# echo ${var##*[.]}
The reason for this is that in fact the content of the variable is "" and you can't remove any "part before the dot" because there isn't any dot. But when you try to display this asterisk with the echo -command the shell replaces it with a list of files named along the pattern (i.e. when you specifiy "abc" the pattern is "all files with names starting with "abc").
Therefor you need to not use the asterisk as part of your variables content but the list it produces - and then trim the resulting filenames one at a time with the expression rdtx1 gave you. Like this:
ls | while read filename ; do
echo "filename is: $filename trimmed filename is: ${filename##*[.]}"
done