Sponsored Content
Top Forums Shell Programming and Scripting assigning SED output to a variable = trouble! Post 302233953 by hungryd on Monday 8th of September 2008 08:54:42 PM
Old 09-08-2008
assigning SED output to a variable = trouble!

i'm on a Mac running BSD unix.

i have a script in which i ask the user to input the name of a mounted volume. i then call SED to substitute backslashes and spaces in place of the spaces. that looks like this:

echo "Enter the name of the volume"
read Volume
echo "You've chosen \"$Volume\""
# remove spaces from name of Volume
echo $Volume | sed 's/ /\\ /g'

if i enter "old mac hd" for the volume name when prompted, it returns with:
"old/ mac/ hd" which is perfect!

but... if i then want to assign this output to a variable for later use, it doesn't work:

uVolume=`echo "$Volume" | sed 's/ /\\ /g'`
echo $uVolume

this returns:
"old mac hd" and NOT "old/ mac/ hd" as i'd like. and, as i'll be using the full directory path in a later portion of the script, i kinda need those backslashes!

i'm assuming that i'm missing simple syntax here. thoughts/comments/questions?
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Assigning output of command to a variable

Hi, I'm trying to assign the output of a command to a variable and then concat it with another string, however, it keeps overwriting the original string instead of adding on to the end of the string. Contents of test.txt --> This is a test var1="`head -n 1 test.txt`" echo $var1 (This is a... (5 Replies)
Discussion started by: oma04
5 Replies

2. Shell Programming and Scripting

assigning command output to a shell variable

I have the sql file cde.sql with the below contents: abcdefghij abcwhendefothers sdfghj when no one else when others wwhen%others exception when others Now I want to search for the strings containing when others together and ceck whether that does not occur more than once in the... (2 Replies)
Discussion started by: kprattip
2 Replies

3. Shell Programming and Scripting

assigning nawk output to shell variable

Hello friends, I doing the follwing script , but found problem to store it to a shell variable. #! /bin/sh for temp in `find ./dat/vector/ -name '*.file'` do echo $temp nawk -v temp=$temp 'BEGIN{ split(temp, a,"\/"); print a}' done output: ./dat/vector/drf_all_002.file... (6 Replies)
Discussion started by: user_prady
6 Replies

4. Shell Programming and Scripting

Assigning output of command to a variable in shell

hi, I want to assign find command result into some temporary variable: jarPath= find /opt/lotus/notes/ -name $jarFile cho "the jar path $jarPath" where jarPath is temporary variable. Can anybody help on this. Thanks in advance ----Sankar (6 Replies)
Discussion started by: sankar reddy
6 Replies

5. Shell Programming and Scripting

Assigning output to a variable

I am new to unix shell scripting. I was trying to convert each lines in a file to upper case. I know how to convert the whole file. But here i have to do line by line. I am getting it in the below mentioned script #!/bin/bash #converting lower to upper in a file #tr "" "" <file1... (3 Replies)
Discussion started by: jpmena
3 Replies

6. Shell Programming and Scripting

Assigning output of a command to variable

When I run time -p <command>, it outputs: real X.XX user X.XX sys X.XXwhere X.XX is seconds. How I can take just that first number output, the seconds of real time, and assign that to a variable? (9 Replies)
Discussion started by: jeriryan87
9 Replies

7. Shell Programming and Scripting

Piping and assigning output to a variable in Perl

Hi All, I am trying to convert the below Csh code into Perl. But i have the following error. Can any expert help ? Error: ls: *tac: No such file or directory Csh set $ST_file = `ls -rt *$testid*st*|tail -1`; Perl my $ST_file = `ls -rt *$testid*st*|tail -1`; (10 Replies)
Discussion started by: Raynon
10 Replies

8. Shell Programming and Scripting

Assigning output from awk to variable

I have a script whose contents are as below result= awk 's=100 END {print s }' echo "The result is" $result The desired output is The result is 100 My script is running without exiting and i am also not getting the desired output. Please help (5 Replies)
Discussion started by: bk_12345
5 Replies

9. Shell Programming and Scripting

Assigning bc output to a variable

I'm converting decimal to integer with bc, and I'd like to assign the integer output from bc to a variable 'val'. E.g. In the code below: If b is 5000.000, lines 6 and 8 will output: 5000 (5000.000+0.5)/1 | bc I'd like val to take the value 5000 though, rather than 5000.000 Does someone... (3 Replies)
Discussion started by: pina
3 Replies

10. Shell Programming and Scripting

Trouble Assigning Variable with Function

OSX 10.9 Good morning/afternoon/evening. I'm hoping to get some insight on assigning a variable when calling a function. The code below looks at my array and checks if the path exists. My actual code will have multiple arrays and I would like to define a specific array when I call the... (6 Replies)
Discussion started by: sudo
6 Replies
Gnome2::VFS::Volume(3pm)				User Contributed Perl Documentation				  Gnome2::VFS::Volume(3pm)

NAME
Gnome2::VFS::Volume - Abstraction for a mounted file system or a network location HIERARCHY
Glib::Object +----Gnome2::VFS::Volume METHODS
string = $volume->get_activation_uri integer = $a->compare ($b) o $b (Gnome2::VFS::Volume) Gnome2::VFS->connect_to_server ($uri, $display_name, $icon) o $uri (string) o $display_name (string) o $icon (string) string = $volume->get_device_path devicetype = $volume->get_device_type string = $volume->get_display_name drive = $volume->get_drive $volume->eject ($func, $data=undef) o $func (scalar) o $data (scalar) string = $volume->get_filesystem_type string = $volume->get_hal_udi Since: vfs 2.8 boolean = $volume->handles_trash string = $volume->get_icon unsigned = $volume->get_id boolean = $volume->is_mounted boolean = $volume->is_read_only boolean = $volume->is_user_visible $volume->unmount ($func, $data=undef) o $func (scalar) o $data (scalar) volumetype = $volume->get_volume_type ENUMS AND FLAGS
enum Gnome2::VFS::DeviceType o 'unknown' / 'GNOME_VFS_DEVICE_TYPE_UNKNOWN' o 'audio-cd' / 'GNOME_VFS_DEVICE_TYPE_AUDIO_CD' o 'video-dvd' / 'GNOME_VFS_DEVICE_TYPE_VIDEO_DVD' o 'harddrive' / 'GNOME_VFS_DEVICE_TYPE_HARDDRIVE' o 'cdrom' / 'GNOME_VFS_DEVICE_TYPE_CDROM' o 'floppy' / 'GNOME_VFS_DEVICE_TYPE_FLOPPY' o 'zip' / 'GNOME_VFS_DEVICE_TYPE_ZIP' o 'jaz' / 'GNOME_VFS_DEVICE_TYPE_JAZ' o 'nfs' / 'GNOME_VFS_DEVICE_TYPE_NFS' o 'autofs' / 'GNOME_VFS_DEVICE_TYPE_AUTOFS' o 'camera' / 'GNOME_VFS_DEVICE_TYPE_CAMERA' o 'memory-stick' / 'GNOME_VFS_DEVICE_TYPE_MEMORY_STICK' o 'smb' / 'GNOME_VFS_DEVICE_TYPE_SMB' o 'apple' / 'GNOME_VFS_DEVICE_TYPE_APPLE' o 'music-player' / 'GNOME_VFS_DEVICE_TYPE_MUSIC_PLAYER' o 'windows' / 'GNOME_VFS_DEVICE_TYPE_WINDOWS' o 'loopback' / 'GNOME_VFS_DEVICE_TYPE_LOOPBACK' o 'network' / 'GNOME_VFS_DEVICE_TYPE_NETWORK' enum Gnome2::VFS::VolumeType o 'mountpoint' / 'GNOME_VFS_VOLUME_TYPE_MOUNTPOINT' o 'vfs-mount' / 'GNOME_VFS_VOLUME_TYPE_VFS_MOUNT' o 'connected-server' / 'GNOME_VFS_VOLUME_TYPE_CONNECTED_SERVER' SEE ALSO
Gnome2::VFS, Glib::Object COPYRIGHT
Copyright (C) 2003-2007 by the gtk2-perl team. This software is licensed under the LGPL. See Gnome2::VFS for a full notice. perl v5.14.2 2011-11-15 Gnome2::VFS::Volume(3pm)
All times are GMT -4. The time now is 05:10 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy