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
MRTG-SQUID(1)							       mrtg							     MRTG-SQUID(1)

NAME
mrtg-squid - using mrtg to monitor Squid DESCRIPTION
Squid 2.3 knows SNMP and you can therefore use mrtg to monitor it quite easily. I have made some modifications to mrtg which simplify this. My work is based on earlier modification made by: matija.grabnar@arnes.si and kostas@nlanr.net. MODIFICATIONS
I added new code for displaying correct units to the previous patches "perminute" and "perhour" ("option" tokens), which allows other mea- surement in addition to "persecond". Then I created a new option token "dorelpercent" which allows the calculation of the percentage of IN-stream / OUT-stream on the fly and then displays it on a fixed scale from 0% to 100%. For my requirements, this does good work. Maybe someone wants a floating scale. It should not be a problem to implement it, too (but give me an option to keep my fixed scale). If IN-stream is always less than OUT-stream both lines (OUT-stream and relative percent) are always displayed on top of IN-stream bulk. Otherwise this option makes no sense. With this option you can display hitrates, errorrates (for router monitoring: rel. droprates) easily now. If you use this options please consider that you need a 5th colourname/value pair in your Colours statements! Due to some discussion on this list, I have implemented two tokens too: "kilo" and "kMG" "kilo" should contain the value of k (1000 or 1024), where 1000 is the default. "kMG" is a comma separated list of multiplier prefixes, used instead of "", "k", "M", "G", "T" on the MRTG display. Leave the place free, if you want no prefix. Also an incomplete list of OIDs for the new SQUID release is added. I hope you enjoy it. CONFIG EXAMPLE
You can measure responsetimes in ms and display it with MRTG correctly with: kMG[measure-ms]: m,,k,M,G,T short[measure-ms]: s You can display now MB/s as 1024*1024 B/s with: kilo[volume]: 1024 A sample config for squid: Target[proxy-hit]: cacheHttpHits&cacheProtoClientHttpRequests:public@proxy Title[proxy-hit]: HTTP Hits PageTop[proxy-hit]: <H2>proxy Cache Statistics: HTTP Hits / Requests</H2> Suppress[proxy-hit]: y LegendI[proxy-hit]: HTTP hits LegendO[proxy-hit]: HTTP requests Legend1[proxy-hit]: HTTP hits Legend2[proxy-hit]: HTTP requests YLegend[proxy-hit]: perminute ShortLegend[proxy-hit]: req/min Options[proxy-hit]: nopercent, perminute, dorelpercent Target[proxy-srvkbinout]: cacheServerInKb&cacheServerOutKb:public@proxy Title[proxy-srvkbinout]: Cache Server Traffic In / Out PageTop[proxy-srvkbinout]: <H2>Cache Statistics: Server traffic volume (In/Out) </H2> Suppress[proxy-srvkbinout]: y LegendI[proxy-srvkbinout]: Traffic In LegendO[proxy-srvkbinout]: Traffic Out Legend1[proxy-srvkbinout]: Traffic In Legend2[proxy-srvkbinout]: Traffic Out YLegend[proxy-srvkbinout]: per minute ShortLegend[proxy-srvkbinout]: b/min kMG[proxy-srvkbinout]: k,M,G,T kilo[proxy-srvkbinout]: 1024 Options[proxy-srvkbinout]: nopercent, perminute AUTHOR
Andreas Papst <andreas.papst@univie.ac.at> Dirk-Luder Kreie <deelkar@gmx.de> 2.16.2 2008-05-16 MRTG-SQUID(1)
All times are GMT -4. The time now is 09:36 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy