Any time you want to assign a value to a variable in a shell script using Bourne shell syntax (you haven't told us what operating system and shell you're using, but from what you have shown us I assume you're using a shell that is based on Bourne shell syntax), you use a shell variable assignment statement, i.e.:
If you want to get the next to the last component of a pathname containing at least two components using the dirname and basename utilities, you could use something like:
which produces the output:
With any shell that supports the shell variable expansions required by the POSIX standards, one can get a faster response avoiding the two subshells and two invocations of external utilities by just using features of the shell programming language:
which produces the output:
Note also that the comments in your code do not come close to describing what the code you have shown us actually does. This makes it hard to figure out what you are really trying to do. For example, your comments talk about removing extensions, but none of the code you have shown us makes any attempt to remove filename extensions.
I will try to clarify one of my issues.
I need to get item selected from whiptail (menu) --checklist
Here is my last simplified code using "while read" and it sort off works retrieving values from menu.
Three issues
1. It will print continually - after "enter" and only first parameter passed to the function , not the (menu) selection and only when --separate-output is implemented
2. It will print selection in "" after "enter", then it will print first parameter passed to the function, continually after each enter press when --separate-output is NOT implemented.
3. It will never "terminate " the "while read "
I can live with "" around selection , but need to stop the "while read".
Any suggestion will be appreciated.
Cheers
BTW
I run plain bash on Raspian OS.
My code is under construction / troubleshooting and I do concentrate on issues
not on keeping the code in sync with comments. It should not be a big issue if discussion participants bypass the comment too if the are not relevant.
hi all,
trying to get this to work but im struggling abit and wondered if you can help me out
basically i have created a variable
base='basename $dir'
echo "please specify full path to directory you want to be made into a tar"
read -e dir
tar -cf... (7 Replies)
Hello,
I am trying to print out the first string matching query with grep and I need your help.
My scenario:
Database
John F
4433 Street No 88 CA
Elisabeth Taylor
7733 Street No 26 ON
Jack Nicholson
0133 Green Park No 34 AR
John F 2
9399 Southpark No 02D UT
test.sh... (6 Replies)
I have a date column as 06302015 but I need to have variable which extracts 063015.
Am trying something like below but it is not assigning
Please let me know if am missing something. Thanks in advance.
################################
#!/usr/bin/ksh
DT=06302015
... (7 Replies)
Unable to get the value to a variable.
set -x
cd $HOME
echo "Enter the server name"
read a
echo $a
i=4
j=1
k = ps -ef | awk '/server1/{ print $4 }' | tail -$i | head -$j`
echo $k
When I do the same in command line it works, however the same does not work when I provide that in the... (1 Reply)
my script is some thing like this
i11="{1,2,3,4,5,6,7,8,9,10,11,}"
echo "enter value"
read value ..............suppose i11
x="$value"
echo "$($value)" .............the echo should be {1,2,3,4,5,6,7,8,9,10,11,}
but its showing "i11" only.
plz help me out to get desired... (10 Replies)
Hi folks.
I have this variable called FirstIN that contains something like this: 001,002,003,004...
I am trying to assign the content of this variable into ModifiedIN but with the following format : 001 002 003 004...(changing the commas for spaces)
I thought about using sed but i am not... (17 Replies)
can we make a global variable and store character values and add other values to that variable ?? for example
a="hello, John"
and can we add value ". How are you? so
a can have
"hello, John. How are you?"
can someone help me?? (2 Replies)
hi all,
in ksh, how do i assign the output of a find command to a variable, e.g
am trying something like this :
totalNoFiles=$(print find ./ -name "SystemOut*.log");
but when i echo $totalNoFiles it displays
find ./ -name "SystemOut*.log"
instead of the total number of... (2 Replies)
Hello all,
Can somebody explain to me how set up a basename and dirname variable to simplify this script. I currently have a 'infile' with the contents of FTTPDataPVC_ & BaaisDSLFeed. I need to add a basename and or dirname variable so that any additions can be made through the infile and not... (1 Reply)
Another newbie to Unix scripting Q..
How do you assign a value resulting from a command, such as awk, to a variable.
I am currently trying:-
$awk '{print $1}' file1 > variable1
with no change to $variable1.
The line:
$awk '{print $1}' file1
does print the first line of the... (3 Replies)