Discussion:
[OT] Issue with a Mac Shell script
Jean-Luc Arnaud
2018-09-26 15:58:15 UTC
Permalink
Hi all,

I'm trying to code a Unix script in order to eject a RAM Disk.

Using:

diskutil list | grep 'RAM Disk' | awk '{print $6}'

I'm able to get the disk ref (i.e. Disk1).

But trying:

diskutil eject |diskutil list | grep 'RAM Disk' | awk '{print $6}'

I can't achieve what I need.

Maybe, I should use a variable, but I don't know how to assign diskutil
list | grep 'RAM Disk' | awk '{print $6}' to a variable.

TIA for any help.
--
Jean-Luc Arnaud
Tim Jones
2018-09-27 17:14:12 UTC
Permalink
You will need to put the disk into a Xojo variable:

theShell.Execute "diskutil list | grep 'RAM Disk' | awk '{print $6}'"
If theShell.ErrorCode = 0 Then
ejectDevice = NthFieldB(ReplaceLineEndings(theShell.ReadAll, EndOfLine), EndOfLine, 1)
Else
// the diskutil command failed
End If
theShell.Execute "diskutil eject " + ejectDevice
...

Tim
Post by Jean-Luc Arnaud
Hi all,
I'm trying to code a Unix script in order to eject a RAM Disk.
diskutil list | grep 'RAM Disk' | awk '{print $6}'
I'm able to get the disk ref (i.e. Disk1).
diskutil eject |diskutil list | grep 'RAM Disk' | awk '{print $6}'
I can't achieve what I need.
Maybe, I should use a variable, but I don't know how to assign diskutil list | grep 'RAM Disk' | awk '{print $6}' to a variable.
TIA for any help.
--
Jean-Luc Arnaud
Jose Maria Terry Jimenez
2018-09-27 17:37:06 UTC
Permalink
Ok i see what you want with Tim's answer, so i'd try:

diskutil eject `diskutil list | grep 'RAM Disk' | awk '{print $6}'`

the output of the command between ` and ` is replaced in that position

Hope *this* helps :-)
Post by Tim Jones
theShell.Execute "diskutil list | grep 'RAM Disk' | awk '{print $6}'"
If theShell.ErrorCode = 0 Then
ejectDevice = NthFieldB(ReplaceLineEndings(theShell.ReadAll, EndOfLine), EndOfLine, 1)
Else
// the diskutil command failed
End If
theShell.Execute "diskutil eject " + ejectDevice
...
Tim
Post by Jean-Luc Arnaud
Hi all,
I'm trying to code a Unix script in order to eject a RAM Disk.
diskutil list | grep 'RAM Disk' | awk '{print $6}'
I'm able to get the disk ref (i.e. Disk1).
diskutil eject |diskutil list | grep 'RAM Disk' | awk '{print $6}'
I can't achieve what I need.
Maybe, I should use a variable, but I don't know how to assign diskutil list | grep 'RAM Disk' | awk '{print $6}' to a variable.
TIA for any help.
--
Jean-Luc Arnaud
Jean-Luc Arnaud
2018-09-28 13:10:04 UTC
Permalink
Great!

Yes, Jose Maria, this is exactly what I need.

Many thanks

And thanks to Tim for his reply.

Jean-Luc Arnaud
Post by Jose Maria Terry Jimenez
diskutil eject `diskutil list | grep 'RAM Disk' | awk '{print $6}'`
Jose Maria Terry Jimenez
2018-09-28 19:28:54 UTC
Permalink
Glad to help

You're welcome
Post by Jean-Luc Arnaud
Great!
Yes, Jose Maria, this is exactly what I need.
Many thanks
And thanks to Tim for his reply.
Jean-Luc Arnaud
Post by Jose Maria Terry Jimenez
diskutil eject `diskutil list | grep 'RAM Disk' | awk '{print $6}'`
Jose Maria Terry Jimenez
2018-09-27 17:32:40 UTC
Permalink
Post by Jean-Luc Arnaud
Hi all,
I'm trying to code a Unix script in order to eject a RAM Disk.
diskutil list | grep 'RAM Disk' | awk '{print $6}'
I'm able to get the disk ref (i.e. Disk1).
diskutil eject |diskutil list | grep 'RAM Disk' | awk '{print $6}'
I can't achieve what I need.
Maybe, I should use a variable, but I don't know how to assign
diskutil list | grep 'RAM Disk' | awk '{print $6}' to a variable.
TIA for any help.
I suppose you don't want to parse the output of diskutil eject (thru
pipe) to diskutil list, so you could try:

diskutil eject && diskutil list | grep 'RAM Disk' | awk '{print $6}'

Executes diskutil eject and if it works then the rest ( diskutil list |
grep 'RAM Disk' | awk '{print $6}' )

Hope helps, not tested
Continue reading on narkive:
Loading...