Sponsored Content
Top Forums UNIX for Dummies Questions & Answers Scripting Question (For Loop) Post 302953021 by neutronscott on Tuesday 25th of August 2015 01:36:49 AM
Old 08-25-2015
Quote:
Originally Posted by shah9250
However, what do you mean by properly split list of files?
See the following shell session example:

Code:
mute@tiny:~$ mkdir shah9250
mute@tiny:~$ cd shah9250/
mute@tiny:~/shah9250$ touch 'file with spaces'
mute@tiny:~/shah9250$ for f in $(ls); do echo "work on [$f]"; done
work on [file]
work on [with]
work on [spaces]
mute@tiny:~/shah9250$ for f in *; do echo "work on [$f]"; done
work on [file with spaces]

We know there is only one file and the loop should only be called once, but with that use of $(ls) it's not. Quoting and word splitting are the toughest parts of learning the shell, in my opinion. Once that clicks things are much easier.

Quote:
Originally Posted by shah9250
Also what is a glob? Also you used a wildcard (*) in the "for" statement, so how does the variable $file receive input?
Glob is filename expansion. * is a wildcard that matches anything. You can simply do echo * or echo *.txt to show all files or all files ending in .txt. My meaning wasn't to distract from the for loop, just for down the road you'll want to use best practices. Filenames can contain any character except the NUL character and the path delimiter / and a great deal of care must be taken to make robust scripts.

I cannot recommend Greg's wiki enough. The bash guide on the site is excellent value for the price: BashGuide - Greg's Wiki
This User Gave Thanks to neutronscott For This Post:
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

new to shell scripting: whats wrong with my if loop

#!/bin/bash for file in $HOME/*; do if ; then rm -i $file > /dev/null echo "$?" echo "$file has been deleted" fi done Been trying to learn shell scripting for a week or so now, when i run the script it doesnt display an error message, seems like it runs fine, however it doesnt delete... (10 Replies)
Discussion started by: stride6
10 Replies

2. Solaris

Problem in for loop of shell scripting in solaris

Hi below is my script for((i=0;i<=$TOTAL;i++)) do echo "IP's created are $s1.$s2.$s3.$s4" s4=`expr $s4 + 1` done where s1,2,3,4 are input varibles below error occurs while running the script syntax error at lin 11: '(' unexpected ... (12 Replies)
Discussion started by: krevathi1912
12 Replies

3. UNIX for Dummies Questions & Answers

Loop till you find a string in a fine <-- Need Help New to Unix Scripting

Guys - I am new to Unix scripting and am in need for a script that does the following. I have bits and pieces created and tested but i am just having a little difficult time getting it all together. - Loop through till it finds a string in a specific file. Any help is greatly appreciated. ... (1 Reply)
Discussion started by: mrehman
1 Replies

4. Shell Programming and Scripting

while loop in shell scripting

Hi, I have a doubt in usage of while loop in Shell script as Iam new to this. My requirement is that,I have two different directories containing some files which move files to other folder after parsing is done. In my script i wanted to add a while loop which checks for the count in these two... (5 Replies)
Discussion started by: jyothi_wipro
5 Replies

5. Shell Programming and Scripting

BASH loop inside a loop question

Hi all Sorry for the basic question, but i am writing a shell script to get around a slightly flaky binary that ships with one of our servers. This particular utility randomly generates the correct information and could work first time or may work on the 12th or 100th attempt etc !.... (4 Replies)
Discussion started by: rethink
4 Replies

6. Shell Programming and Scripting

Clarification on if loop in Shell scripting

Hi, I'm using Ksh and I'm seeing some of code in my programme as given below. Could you please let me know whats is this meeaing ? (I'm new to this unix) grep "1034" /u/kkk/bin/temp5.lst|cut -c1-2 >/u/kkk/bin/temp6.lst if then echo "" ... (2 Replies)
Discussion started by: shyamu544
2 Replies

7. Shell Programming and Scripting

while loop shell scripting help

hi i was wondering if someone can help me with a while loop..i have been looking at this for hours and dont no wut to do.. i have to make a menu style.. to have a beeter understanding i have linked a photo at the bottom... http://www.mypicx.com/uploadimg/772204432_08022011_1.pngand then ... (1 Reply)
Discussion started by: beerpong1
1 Replies

8. Homework & Coursework Questions

shell scripting while loop lab 15 help

hi.. this is shell scripting lab15.sh i dont understand this lab i am at the screen shot part. i was wondering if someone can take a quick look at this lab i have linked the doc below. i dont know where to start i have did the Required Errorlevels Errorlevel # but dont... (1 Reply)
Discussion started by: beerpong1
1 Replies

9. Shell Programming and Scripting

For loop scripting

Hi there again, I need some help in figuring out how to execute a for loop command to come up with my desired output. I have individual monthly files and a single file containing a list of location data for 1 year. I want to do a loop where for each monthly file say Jan.hdf, if will read the... (8 Replies)
Discussion started by: ida1215
8 Replies

10. Shell Programming and Scripting

Expect Scripting Loop Argument Desperately Needed!

I am trying to create an Expect script that does the following: 1) Telnets to an IP address and logs in with user ID and Password 2) Issue a CLI command to the server that will output data of which I am particularly interested in a DS1 clock 'Slips' value. I want to be able to keep issuing... (0 Replies)
Discussion started by: dwightlaidler
0 Replies
ossmix(1)							 OSS User Commands							 ossmix(1)

NAME
ossmix - Open Sound System command-line mixer program. SYNOPSIS
ossmix [-d <dev#>] [-achqD] [control name] [value] DESCRIPTION
ossmix is a simple command-line mixer utility that is used to display the mixer settings of physical and virtual audio devices. OSS version 4 has an extended mixer API which supports some device specific features that may not available using other mixer applications. OPTIONS
-D Display device information. -a Dump mixer settings for all mixers (normal format). -c Dump mixer settings for all mixers (command format). -h Display usage information. -q Quiet mode. -v[1|2] Verbose mode. -v2 prints more detailed infoamation than -v1. ctrl# value Change value of a mixer control. <no arg> Display current/possible settings. USAGE
ossmix without any arguments displays the current settings of the default mixer device (usually the motherboard sound chip). This printout can also be used to find out the supported control names and their possible values. Currently all controls accept an ON/OFF value, a mono value (0 to 100) or a stereo value (left:right where both channel volumes can be between 0 and 100). The value can also be expressed in a relative form (e.g. +1 to add 1 to the previous volume). An ON/OFF control can also receive a TOGGLE value. If a control has a name in quotes following the normal output, than the name can be used instead of the control when setting a value. The following is a sample printout produced by ossmix: Selected mixer 0/Creative AudioPCI Known controls are: vol <both/leftvol>[:<rightvol>] (currently 50:50) pcm <both/leftvol>[:<rightvol>] (currently 50:50) speaker <monovol> (currently 21) line <both/leftvol>[:<rightvol>] (currently 32:32) line.rec ON|OFF (currently OFF) mic <monovol> (currently 16) mic.rec ON|OFF (currently ON) cd <both/leftvol>[:<rightvol>] (currently 100:100) cd.rec ON|OFF (currently OFF) pcm2 <both/leftvol>[:<rightvol>] (currently 75:75) line1 <both/leftvol>[:<rightvol>] (currently 32:32) line1.rec ON|OFF (currently OFF) line2 <monovol> (currently 32) line2.rec ON|OFF (currently OFF) line3 <monovol> (currently 0) line3.rec ON|OFF (currently OFF) mic.micboost ON|OFF (currently ON) mic.micbias ON|OFF (currently ON) mute.pcmmute ON|OFF (currently OFF) mute.pcm2mute ON|OFF (currently OFF) mute.micmute ON|OFF (currently OFF) mute.cdmute ON|OFF (currently OFF) mute.linemute ON|OFF (currently OFF) mute.line1mute ON|OFF (currently OFF) mute.line2mute ON|OFF (currently OFF) mute.line3mute ON|OFF (currently OFF) SELECTING MIXER DEVICE
It's possible to select the mixer device by using the -d<mixernumber> command line argument. This argument (when used) should be the first one on the command line. By default the mixer number 0 will be accessed. To find the available mixer devices, type ossinfo -x and look under the Mixers heading for available mixer devices. CHANGING MIXER SETTINGS
Changing the values is done just like with the original "mixer" applet. For example: ossmix pcm 50:60 The above sets the pcm control (audio playback volume) so that the left channel volume is 50 and the right channel volume is 60. With just "ossmix pcm 50" the both channel volumes will be set to 50. In addition to the old mixer there are now some (usually ON/OFF) settings. These settings are device specific and don't work with all soundcards. The easiest way to find them out is to start ossmix without command line arguments (other than -d#). Some control names contain a dot ("."). This dot is required when changing the value. For example: "ossmix -d0 mic.micboost ON". EXAMPLES
ossmix vol 50 Set the vol control volume to 50. If the pcm control is a stereo control, than both channels will be set to 50. ossmix vol 50:60 Set the vol control so that the left channel volume is 50 and the right channel volume is 60. ossmix vol +2 Raise vol volume by 2. ossmix -- vol +2:-2 Raise the left channel volume by 2, and lower right channel volume by 2. The "--" is needed on some systems so that the "-2" won't be mistaken for a parameter. ossmix micboost ON Set micboost to ON. ossmix micboost TOGGLE Toggle micboost. ossmix mplayer +2 Raise mplayer volume by 2. This would only work if mplayer is using the virtual mixer. FILES
/usr/bin/ossmix SEE ALSO
ossdevlinks(1), ossxmix(1), savemixer(1) AUTHOR
4Front Technologies 16 December 2012 ossmix(1)
All times are GMT -4. The time now is 04:21 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy