Sponsored Content
Top Forums Shell Programming and Scripting Assigning basename result to another variable Post 303021527 by annacreek on Sunday 12th of August 2018 08:42:11 AM
Old 08-12-2018
Assigning basename result to another variable

This is a two part request for an assistance.



I am not sure how retrieve value from basename command - line 270 -so in can be output as variable CLI_COMMAND - line 250 in whiptail input box.



As coded I can input from keyboard ( stdin?) into input box using redirection.

I can extract wanted values using "do dir..." and print them to terminal - stdout.


What I need help with is assigning results of "do dir..." namebase to another variable.



Perhaps the answer is in output redirection, but I do not know where in the code it should be applied.





Code:
# start of menu 13 processing 

   	 	 	 	   13)
  248                echo "TEMPLATE Option 13"
  249 #stupid spaces AGAIN  
  250 CLI_COMMAND=$(whiptail --title "Test Free-form Input Box" \
  251 --inputbox "Enter command " 10 60 usb_devices   3>&1 1>&2 2>&3)
  252 # 1>&1 2>&2 3>&3  
  253 exitstatus=$?
  254 if [ $exitstatus = 0 ]; then
  255     echo "Processing commmand " $CLI_COMMAND
  256 else
  257     echo "You chose Cancel."
  258 fi
  259 echo "process command START " $CLI_COMMAND
  260 $CLI_COMMAND     #TOK  
  261 pause   
  262  echo "process command END " $CLI_COMMAND
    263 pause  
  264 # extract value at * (?)  
  265 # for  directory  *  
  266  for dir in /sys/class/net/*/wireless; do
  267 #if the file *  is -d directory (?)  
  268     if [ -d "$dir" ]; then
  269 #extract only   base , no extensions  
  270       basename "$(dirname "$dir")"
  271       echo $?   # print  exist status 0  OK   
  272 # don;t work print empty line echo   "$dirname"  
  273 #echo  entire path  
  274       echo "echo  entire path here " $dir  
  275       if [ "$debug" = true ]
  276          then  
  277          echo "Printed list_wlan_interfaces" $dir  
   
  278          pause  
  279       fi
  280     fi
  281   done
  282                 ;;
  283 #done with menu 13 

  284         14)

------ Post updated 08-12-18 at 07:42 AM ------

FYI

The code was pasted from three parts taken form nano editor via LibreOffice because I could not copy it in one piece in nano.
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Assigning a value to variable

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)
Discussion started by: sirtrancealot
3 Replies

2. Shell Programming and Scripting

Setting basename and dirname variable to simply script.

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)
Discussion started by: liketheshell
1 Replies

3. Shell Programming and Scripting

assigning a variable

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)
Discussion started by: cesarNZ
2 Replies

4. Shell Programming and Scripting

Assigning value to a variable

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)
Discussion started by: bonosungho
2 Replies

5. Shell Programming and Scripting

Removing a character from a variable and assigning it to another variable?

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)
Discussion started by: Stephan
17 Replies

6. Shell Programming and Scripting

problem in assigning value to variable have value fo other variable

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)
Discussion started by: sagar_1986
10 Replies

7. Shell Programming and Scripting

Assigning value to a variable

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)
Discussion started by: venkidhadha
1 Replies

8. Shell Programming and Scripting

Assigning a variable

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)
Discussion started by: weknowd
7 Replies

9. Shell Programming and Scripting

Assigning variable to output gives error with expected result

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)
Discussion started by: baris35
6 Replies

10. Programming

Basename for directory variable

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)
Discussion started by: robertkwild
7 Replies
echo(1B)					     SunOS/BSD Compatibility Package Commands						  echo(1B)

NAME
echo - echo arguments to standard output SYNOPSIS
/usr/ucb/echo [-n] [argument] DESCRIPTION
echo writes its arguments, separated by BLANKs and terminated by a NEWLINE, to the standard output. echo is useful for producing diagnostics in command files and for sending known data into a pipe, and for displaying the contents of envi- ronment variables. For example, you can use echo to determine how many subdirectories below the root directory (/) is your current directory, as follows: o echo your current-working-directory's full pathname o pipe the output through tr to translate the path's embedded slash-characters into space-characters o pipe that output through wc -w for a count of the names in your path. example% /usr/bin/echo "echo $PWD | tr '/' ' ' | wc -w" See tr(1) and wc(1) for their functionality. The shells csh(1), ksh(1), and sh(1), each have an echo built-in command, which, by default, will have precedence, and will be invoked if the user calls echo without a full pathname. /usr/ucb/echo and csh's echo() have an -n option, but do not understand back-slashed escape characters. sh's echo(), ksh's echo(), and /usr/bin/echo, on the other hand, understand the black-slashed escape characters, and ksh's echo() also understands a as the audible bell character; however, these commands do not have an -n option. OPTIONS
-n Do not add the NEWLINE to the output. ATTRIBUTES
See attributes(5) for descriptions of the following attributes: +-----------------------------+-----------------------------+ | ATTRIBUTE TYPE | ATTRIBUTE VALUE | +-----------------------------+-----------------------------+ |Availability |SUNWscpu | +-----------------------------+-----------------------------+ SEE ALSO
csh(1), echo(1), ksh(1), sh(1), tr(1), wc(1), attributes(5) NOTES
The -n option is a transition aid for BSD applications, and may not be supported in future releases. SunOS 5.10 3 Aug 1994 echo(1B)
All times are GMT -4. The time now is 06:40 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy