Sponsored Content
Top Forums UNIX for Advanced & Expert Users Redirection? (I do find some of the strangest things.) Post 302989215 by wisecracker on Tuesday 10th of January 2017 04:41:43 AM
Old 01-10-2017
Redirection? (I do find some of the strangest things.)

(Apologies for any typos.)
Can someone help me with this one please.
I am writing a snippet that will come on here soon to work on OSX, Linux and CygWin but I hit this!

I hope this is lucid enough because I really do not understand what is going on.

Take these few lines:-
Code:
#!/bin/sh
# OR #!/usr/local/bin/dash
> /tmp/noise.raw
> /dev/null 2>&1 cat /tmp/noise.raw > /dev/dsp

And tested in ShellCheck gives this:-
Code:
$ shellcheck myscript
 
Line 3:
> /tmp/noise.raw
^-- SC2188: This redirection doesn't have a command. Move to its command (or use 'true' as no-op).

$

OK so I add a NOP:-
Code:
#!/bin/sh
# OR #!/usr/local/bin/dash
: > /tmp/noise.raw
> /dev/null 2>&1 cat /tmp/noise.raw > /dev/dsp

And tested in ShellCheck gives NO error:-
Code:
$ shellcheck myscript
No issues detected!

$

Why is a redirection to > /dev/null allowed to be a _direct_ redirection and yet : > /tmp/noise.raw requires a NOP?

Next question is this line, > /dev/null 2>&1 cat /tmp/noise.raw > /dev/dsp actually works to hide an OSX error, paraphrasing, 'I don't have permssion to access this' which is obvious as OSX does not have '/dev/dsp'.
This line also runs correctly on CygWin with > /dev/null 2>&1 at the start. So it looks like I have done something correct but don't know why?

TIA.

Barry.
 

6 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

i get the strangest feeling that lilo hates me.

i need to get rid of lilo's splash screen. i've heard that you can edit your /etc/lilo.conf and add this line: <b>append="splash=0"</b> anyway, i did that and i still have a splash screen. any idea why that didn't work, or what is another way to disable the splash screen? okay, -nydel (1 Reply)
Discussion started by: nydel
1 Replies

2. Programming

Complicating things?

So basically what im trying to do is ... Open file, read that file, than try to find .. We or we and replace them with I, but not replace the cases where words contain We or we, such as Went, went, etc a and replace them with the, but not replace the cases where words contain a, such as... (1 Reply)
Discussion started by: bconnor
1 Replies

3. Programming

Question about several things in C

Hey guys, first of all I'd like to say Hi to everyone. I am new here and this is my first post. I have a question about some C stuff. I am in Computer Science and I have an assignment for a UNIX Applications course. It is really complicated, however. We're using the C language for this and... (1 Reply)
Discussion started by: V4D3R
1 Replies

4. UNIX for Advanced & Expert Users

shell redirection in find

hi, i need to clear data off a DOA backup drive. i try this, but just get a file {} in . and no change on the backup drive. bash shell find /mnt/usbbackup -xdev -type f -exec echo `date` > {} \; any ideas? thanks. :) (1 Reply)
Discussion started by: drewnichols
1 Replies

5. UNIX for Dummies Questions & Answers

Just trying to find out a few things ....

Hi everyone Just a couple of quick questions if I may. Can I ask what is meant by "flavours"?? I've come across it many times in the forums and I'm guessing that it is a variery of either Linux or UNIX (I know nil about either) which has developed but not really got a clue. ... (1 Reply)
Discussion started by: Tiramisu
1 Replies

6. Shell Programming and Scripting

Several exec on find send all the output to the last redirection

Example script: find mydir -type f -exec echo {}>aaa \; -exec echo {}>bbb \;The two paths go the the bbb file, while there should be one of them on each file. How should I do it to get it working? (2 Replies)
Discussion started by: Tribe
2 Replies
RAW(8)							       System Administration							    RAW(8)

NAME
raw - bind a Linux raw character device SYNOPSIS
raw /dev/raw/raw<N> <major> <minor> raw /dev/raw/raw<N> /dev/<blockdev> raw -q /dev/raw/raw<N> raw -qa DESCRIPTION
raw is used to bind a Linux raw character device to a block device. Any block device may be used: at the time of binding, the device driver does not even have to be accessible (it may be loaded on demand as a kernel module later). raw is used in two modes: it either sets raw device bindings, or it queries existing bindings. When setting a raw device, /dev/raw/raw<N> is the device name of an existing raw device node in the filesystem. The block device to which it is to be bound can be specified either in terms of its major and minor device numbers, or as a path name /dev/<blockdev> to an existing block device file. The bindings already in existence can be queried with the -q option, which is used either with a raw device filename to query that one device, or with the -a option to query all bound raw devices. Unbinding can be done by specifying major and minor 0. Once bound to a block device, a raw device can be opened, read and written, just like the block device it is bound to. However, the raw device does not behave exactly like the block device. In particular, access to the raw device bypasses the kernel's block buffer cache entirely: all I/O is done directly to and from the address space of the process performing the I/O. If the underlying block device driver can support DMA, then no data copying at all is required to complete the I/O. Because raw I/O involves direct hardware access to a process's memory, a few extra restrictions must be observed. All I/Os must be cor- rectly aligned in memory and on disk: they must start at a sector offset on disk, they must be an exact number of sectors long, and the data buffer in virtual memory must also be aligned to a multiple of the sector size. The sector size is 512 bytes for most devices. OPTIONS
-q, --query Set query mode. raw will query an existing binding instead of setting a new one. -a, --all With -q , specify that all bound raw devices should be queried. -h, --help Display help text and exit. -V, --version Display version information and exit. BUGS
The Linux dd(1) command should be used without the bs= option, or the blocksize needs to be a multiple of the sector size of the device (512 bytes usually), otherwise it will fail with "Invalid Argument" messages (EINVAL). Raw I/O devices do not maintain cache coherency with the Linux block device buffer cache. If you use raw I/O to overwrite data already in the buffer cache, the buffer cache will no longer correspond to the contents of the actual storage device underneath. This is deliberate, but is regarded either a bug or a feature depending on who you ask! NOTES
Rather than using raw devices applications should prefer open(2) devices, such as /dev/sda1, with the O_DIRECT flag. AUTHOR
Stephen Tweedie (sct@redhat.com) AVAILABILITY
The raw command is part of the util-linux package and is available from https://www.kernel.org/pub/linux/utils/util-linux/. util-linux August 1999 RAW(8)
All times are GMT -4. The time now is 01:08 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy