- Strength to Increase Rep
- +0
- Strength to Decrease Rep
- -0
- Upvotes Received
- 6
- Posts with Upvotes
- 5
- Upvoting Members
- 6
- Downvotes Received
- 6
- Posts with Downvotes
- 6
- Downvoting Members
- 4
Shell programmer and author, web designer and coder, cryptic cruciverbalist, chess instructor
138 Posted Topics
Re: Which command can take input from stdin? Under what circumstances? | |
Re: The best way is to configure the program that creates the file to use the ISO standard date format: YYYY-MM-DDTHH:MM:SS Then the sort command will do the job. | |
Re: cpfile=$HOME/bin/cpfile dest=/home/abc for file in /tmp/* do printf 'cp "%s" "%s"\n' "$file" "$dest" done > "$cpfile" Use `find` to list files older than 3 days: find "$dest" -type f -mtime +3 | |
Re: If you think you need to know the location of the script, you need to rethink what you are doing. Also, there's no need to use external commands basename and dirname in bash (or any other POSIX shell; use parameter expansion). | |
Re: I'm sure the assignment was due well before this, so here goes: | |
Re: Quote the variable references: awk -v FIELDWIDTHS="$FIELDWIDTHS" -v OFS="$OFS" -v INPUTFILE="$INPUTFILE" -v OUTPUTFILE="$OUTPUTFILE" | |
Re: What language are you using? That doesn't look like any shell script I've ever seen. | |
Re: [indent] To check whether the content of the file contains the string [i].txt[/i]: [CODE] file=content.txt string=.txt if grep -q "$string" "$file" then : ## skip (i.e. do nothing) else : do whatever fi [/CODE] To check whether a filename ends in .txt, use [i]case[/i]: [code] file=whatever case $file in *.txt) … | |
Re: Call the script with the options before the arguments, and parse the options first. | |
Re: No external command is needed: string=123456789012 while IFS= read -n3 z; [[ $z ]] do echo "$z" done <<< "$string" | |
Re: It's a good idea to post your solution so that others may be helped. Here is your script with the minimum changes needed to get it to work: currenthour=$(date "+%-H") echo "$currenthour" if [ "$currenthour" -ge 12 ] && [ "$currenthour" -le 16 ]; then currenttimeofday="Afternoon" elif [ "$currenthour" -gt … | |
Re: Use nested loops: ` for i in {0..4} ## you may need $(seq 4) do for j in {a..e} ## or: for j in a b c d e do printf "%s%s\n" "$i" "$j" done done ` | |
Re: [QUOTE=raul8;1757613] [code] #!/bin/bash str1="/user/test" echo $str1 echo ${str1}/program [/code] I just want to store [U]"/user/test/program"[/U] in a separate variable. But this "/program" can be anything. Above I wrote the simplest version, for just explaining the issue. [/QUOTE] If you want a separate variable, you need another assignment statement: [code] str1=/usr/test … | |
Re: They are "special parameters" available in all Bourne-type shells. See the man page of your shell for more details. | |
Re: This doesn't prompt to overwrite; it does nothing in directories already containing index.html: [code] ndx=index.html find . -type d | while read dir do ( cd "$dir" && [ -s "$ndx" ] || mkindex > "$ndx" ## where mkindex is a script to create index file ) done [/code] | |
Re: Do not use csh for scripting: [url]http://shell.cfaj.ca/?2011-11-30_why_not_csh[/url] | |
Re: Get the book, [I]The AWK Programming Language[/I] by Aho, Kernighan and Weinberger. (They wrote the language; its name is their initials.) | |
Re: [code] awk -F, ' { printf "%-1s %2s %2s %2s %2s %2s\n", $1 ? $1 : 0, $2 ? $2 : 0, $3 ? $3 : 0, $4 ? $4 : 0, $5 ? $5 : 0, $6 ? $6 : 0 }' "$file" [/code] | |
Re: [QUOTE=gispe;833106] Im having a problem with my blog desing: thing is I wanna make a 3-column header, but it wont let me. I've tried resizing the header width and then add 2 more columns, and the header was resized, but the other 2 columns didn't appear, so I gues I … | |
Re: > I was supposed to write a program that reads and writes phone numbers of people to a file called phones.txt. The reading part works. The write part doesn't. I tried to use the cat command because I thought doing cat >> file.txt would simply append to a file. What … | |
Re: [QUOTE=pfm200586;1676335]Ok guys I made the script working but there is one last problem which is the AM and PM I coded the following if statement: [code] if [ $Start -gt 12 ] then Start=`expr $Start -12` "PM"[/code] [/QUOTE] [indent] There's no need to use an external program if you are … | |
Re: [QUOTE=nikita.;1685056]Hi , I want to run a shell script which is present in another user's id after switching it to that user in the same script. but it is not taking it. I m using the su command for that. [code] su - user1 -c "./${HOME}/script1.sh" [/code] it just says … | |
Re: The [I]ftp[/I] command is not designed for use in scripts; it is intended for interactive use. For scripting, use the [I]ncftp[/I] family of commands. (There are also some others, I believe, that are made for scripting.) | |
Re: [indent] The [i]setterm[/i] command is not standard. Standard, but not implented consistently across platforms is [i]tput[/i]. Both of those commands are designed to work with any type of terminal (as specified by the TERM variable). However, the plethora of terminal types has, for all intents and purposes, been reduced to … | |
Re: [indent] Do you know where the files, job_1.e and job_2.e, are? If so, why use [i]find[/i]? [code] for file in job_*.e ## adjust path if necessary do if grep -q "Finished with all tasks." "$file" then : line found; do something else : line not found; do something else fi … | |
Re: When referring to shell scripting, one usually means a Unix shell, and more specifically, one derived from Steven Bourne's 1978 shell. A number of extensions to the Bourne shell were introduced by David Korn in the Korn shell (ksh, ks88 and ksh93). The Korn extensions were the basis of the … | |
Re: [QUOTE=Shruti4444;1528087]Trying to code a shell script for a program testing. i need to check for the existence of particular word in outfile and then proceed further, which i am not able to do. I have wrote the following code. Please tell the corrections.. The control does not pass to the … | |
Re: [QUOTE=griswolf;1481483]$@ is a built in variable that holds [B]all[/B] the command line arguments passed to your script. $1 is just the first command line argument. Here's a useless script that illustrates use of $@[CODE]# Usage: bash thisfile anyfile [anyfile...] for fname in $@; do [/CODE] [/QUOTE] [indent] That will break … | |
Re: [QUOTE=griswolf;1522396]Using bash: This worked fine for my baby test. [/QUOTE] [indent] But it will fail in several places if any filenames contain whitespace. [/indent] | |
Re: [QUOTE=pichels;1510646] Was wondering if I could get help with a shell script I am writing to read in 10 -20 directories from a filesystem and then pause, press any key and then read in another 10 or 20 directories and pause again until I read them all. [code] #!/bin/bash DIRS="/data/cusserv/" … | |
Re: [indent][code] var='"THIS" "THAT" "THIS AND THAT" "THIS AND THIS"' eval "set -- $var" for i do echo $i done [/code] [/indent] | |
Re: [QUOTE=lids05;1482162]I am a novice, so please don't be too technical ! I have written 3 separate scripts which all work OK. I now need to merge them into one big script. I would like to introduce a runtime parameter, to allow me to restart at script2 or script3. I would … | |
Re: [indent] It works for me. But you could simplify the code (there's no need for external commands): [code] LF=' ' mountPoint=`df -h "$pth"` mountPoint=${mountPoint#*"$LF"} [/code] Or, if you want to use a Bourne shell rather than a standard Unix shell: [code] mountPoint=`df -h "$pth" | { read; read -r x; … | |
Re: If you need to know where the script is, there is something wrong with your algorithm. Scripts should be in a directory in your PATH, and you should never need to know where it is. | |
Re: [code] sed '/short_message=/ s/.*short_message=\([^,]*\),.*/\1/' [/code] | |
Re: If you want to use awk, there is the split() function: [code] awk -v t=3m1.057s 'BEGIN { split(t,d,/[m.s]/); minute=d[1]; second=d[2]; millisecond=d[3]; print minute, second, millisecond; }' [/code] Using the shell: [code] ( t=3m1.057s IFS=m.s set -f set -- $t set +f minute=$1 second=$2 millisecond=$3 printf "%s %s %s\n" "$minute" "$second" … | |
Re: [code] #!/bin/bash ## Name: randstring ## Synopsis: randstring [ -n NUM ] [ -l LENGTH ] [ -c CHARSET ] ## Author: Chris F.A. Johnson ## Defaults: length=4 num=4 charset=abcdefghijklmnopqrstuvwxyz rand_char() { RAND_CHAR=${charset:$RANDOM % ${#charset}:1} } rand_word() { local string= while [ ${#string} -lt $length ] do rand_char string=$string$RAND_CHAR done … | |
Re: [indent][code] sed 's/ /,/g' "$file" > "$file.csv" [/code] [/indent] | |
Re: Use percentages, not ems (except as max-width or min-width). | |
Re: [INDENT][CODE] dir=/path/to/1TB/drive IFS=$(printf "\n") zip mdf $(find "$dir" -name '*.mdf') find "$dir" -name '*.mdf' -exec rm {} + [/CODE][/INDENT] | |
Re: [QUOTE=FutureWebDev;1419184]If its only going to be for this one page try using an internal CSS stylesheet with the following: [B]CSS[/B] [CODE]#tdleft { width: 100px; height: 100px; background-color: green; border-radius: 10px 0px 0px 0px; -moz-border-radius: 10px 0px 0px 0px; -webkit-border-top-right-radius: 0px; -webkit-border-bottom-right-radius: 0px; -webkit-border-bottom-left-radius: 0px; } #tdright { width: 100px; height: … | |
Re: Don't use the HTML (or XHTML) tutorial at w3schools: [url]http://cfajohnson.com/webdesign/w3schools/[/url] | |
Re: [QUOTE=manish250;1403437]hello all i hav a script when i print it's execution in some line there is #+ in the starting and somewhere there is #++.can anyone plz tell me about these[/QUOTE] [indent] Please show the script. I have no idea what you are talking about. Are #+ and #++ in … | |
Re: [indent][code] IFS=$'\n' names=( $(find /opt/scripts/ -type f -name "properties.*") ) IFS=$' \t\n' printf "%s\n" "${names[@]}" [/code][/indent] | |
Re: I wouldn't use either tcl or perl; I use the shell. | |
Re: [QUOTE=dev_272000;1161375][CODE]#! /bin/bash ######## Created By - R.Wesley Dev Andrew ######### date=`date +%d-%m-%Y` #echo "Please input date in format dd-mm-yyyy" #read date day=`echo $date | awk -F\- '{print $1}'` month=`echo $date | awk -F\- '{print $2}'` year=`echo $date | awk -F\- '{print $3}'` [/CODE] [/QUOTE] [indent] There no need for awk, … | |
Re: Please supply examples of the input you have and the output you expect. | |
Re: Batch files have nothing to do with shell scripting. Please find an appropriate forum. | |
Re: You need an expression inside [[ ... ]]. Read the bash man page. A better contruct would be to use a case statement. It's not clear from your script exactly what you are trying to do. Please expand. | |
Re: What part of the script is giving you problems? What have you tried so far? What is the format of the input file? |
The End.