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
ACPI_PANASONIC(4)					 BSD/i386 Kernel Interfaces Manual					 ACPI_PANASONIC(4)

NAME
acpi_panasonic -- ACPI hotkey driver for Panasonic laptops SYNOPSIS
To compile this driver into the kernel, place the following line in your kernel configuration file: device acpi_panasonic Alternatively, to load the driver as a module at boot time, place the following line in loader.conf(5): acpi_panasonic_load="YES" DESCRIPTION
The acpi_panasonic driver enables such hotkey facilities of various Panasonic laptops as changing LCD brightness, controlling mixer volumes, entering sleep or suspended state and so on. On the following models it is reported to work: Let's note (or Toughbook, outside Japan) CF- R1N, CF-R2A and CF-R3. It may also work on other models as well. The driver consists of three functionalities. The first is to detect hotkey events and take corresponding actions, which include changing LCD luminance and speaker mute state. The second role is to notify occurrences of the event by way of devctl(4) and eventually to devd(8). The third and last is to provide a way to adjust LCD brightness and sound mute state via sysctl(8). Hotkeys There are 9 hotkeys available on the supported hardwares: Fn+F1 Make LCD backlight darker. Fn+F2 Make LCD backlight brighter. Fn+F3 Switch video output between LCD and CRT. Not supported by the acpi_panasonic driver. Fn+F4 Toggle muting the speaker. Fn+F5 Turn the mixer volume down. Fn+F6 Turn the mixer volume up. Fn+F7 Enter suspend-to-RAM state. Fn+F9 Show battery status. Fn+F10 Enter suspend-to-disk state. Actions are automatically taken within the driver for Fn+F1, Fn+F2 and Fn+F4. For the other events such as mixer control and showing battery status, devd(8) should take the role as described below. devd(8) Events When notified to devd(8), the hotkey event provides the following information: system "ACPI" subsystem "Panasonic" type The source of the event in ACPI namespace. The value depends on the model but typically "\_SB_.HKEY". notify Event code (see below). Event codes to be generated are assigned as follows: 0x81-0x86, 0x89 Fn+F<n> pressed. 0x81 corresponds to Fn+F1, 0x82 corresponds to Fn+F2, and so on. 0x01-0x07, 0x09, 0x1a Fn+F<n> released. 0x01 corresponds to Fn+F1, 0x02 corresponds to Fn+F2, and so on. SYSCTL VARIABLES
The following MIBs are available: hw.acpi.panasonic.lcd_brightness_max The maximum level of brightness. The value is read only and automatically set according to hardware model. hw.acpi.panasonic.lcd_brightness_min The minimum level of brightness. The value is read only and automatically set according to hardware model. hw.acpi.panasonic.lcd_brightness Current brightness level of the LCD (read-write). The value ranges from hw.acpi.panasonic.lcd_brightness_min to hw.acpi.panasonic.lcd_brightness_max. hw.acpi.panasonic.sound_mute A read-write boolean flag to control whether to mute the speaker. The value 1 means to mute and 0 not. SEE ALSO
acpi(4), devd.conf(5), devd(8), sysctl(8) HISTORY
The acpi_panasonic driver first appeared in FreeBSD 5.3. AUTHORS
The acpi_panasonic driver and this manual page were written by OGAWA Takaya <t-ogawa@triaez.kaisei.org> and TAKAHASHI Yoshihiro <nyan@FreeBSD.org>. BSD
September 17, 2009 BSD
All times are GMT -4. The time now is 03:45 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy