Programming :: [bash] Option Followed By Argument List?

Feb 6, 2010

I'd like to pass the following arguments to a bash script in any order:

Code:
myscript -l <country> -r <file1> <file2> ... -o

I read the argument list in a switch shift loop. I figured out how to read the filelist but only if -f is the last option.

how to position the file list anywhere in the argument list?

View 5 Replies


ADVERTISEMENT

Programming :: Bash Shell Read User Argument From Command Line And Test It

Aug 29, 2010

Trying to create a small script that will read user's input, test if user entered some input and if not display some message or display a text using user's input.

The script is the following but i get an error saying "[: 6: =: argument expected"

View 12 Replies View Related

Programming :: List 10 Lines By Same In Bash?

Mar 30, 2010

I have a file witch I need to list 10 line by 10 lines with something like press enter to go on in between.
Well, the problem is that i have absolutely no idea on how to implement this.

Can you give me some points?

View 3 Replies View Related

Programming :: List Files In Bash + Add Url Before Them?

Dec 8, 2010

I am an uploader to a various hosts, so this tiny script me a lot. I make a rar archive and split files with 100mb. I could get 3-4 or even 76 parts of rar files and it would take me some time to paste all these urls to remote upload function of filehosting sites. For example:

Code:

server:/home/cober/downloads/teevee# ls -al
total 358784
drwxrwxrwx 2 root root 4096 Dec 8 19:38 .

[code]....

View 1 Replies View Related

Programming :: Bash: Populate A List Of Arbitrarily Named Files?

Mar 14, 2010

How to build a list of files under a directory that may have any permissible characters in the name, that is anything except NUL? The only possible (?) bash data structure to contain a list of such names is an array because NUL cannot be used as a list item separator so no X-separated list can safely be used; there is no "X" that might not be part of a file name. OK -- but how to populate such an array? Here's what I've tried.

Code:

#!/bin/bash
# Set up test files
dir=$(mktemp -d "/tmp/${0##*/}.XXXXXX")
touch $dir/foo $dir/bar

[code].....

View 10 Replies View Related

Programming :: Use Zenity In A Bash Script To Display A .csv File Using '--list'?

Jul 22, 2010

I'm trying to use zenity in a bash script to display a .csv file using '--list' to allow the user to edit some of the values.I can display it fine but i'm unsure how to edit the data? all i can get is whichever line is highlited when hitting ok on the zenity dialog to print.the data in the csv is arranged:

<prod>,<disc>,<qty>,<type>,<location>

View 1 Replies View Related

Programming :: BASH Read Text List Zip Files Into A Single Archive?

Jul 22, 2010

AKA "zipping on the fly .. the slow-as-molasses way." The list includes full pathnames to each file, and they're all in subfolders of the same parent folder (which, unfortunately, is not the root folder of the drive or system on which the files reside). A cleaned-up and radio-ready portion of the list looks like

Quote:

.../taiga/ahqr-va-choyvp/bv0884-073.jpg
.../taiga/ahqr-va-choyvp/bv2635-073.jpg
.../taiga/ahqr-va-choyvp/bv3067-175.jpg

[code]....

What I'd like to be able to do is zip all the files in the list into a single archive, to avoid the step of having to copy them to the same location (presumably another folder on the HD) and then zip that folder. I'm more inclined to make provisions about extracting to a single folder at some other time. Is this possible in BASH, or would I have to consider a faster, more robust scripting language such as python or perl?

View 8 Replies View Related

Server :: Option -m: Invalid Argument Near Character 14

Nov 26, 2010

Option -m: Invalid argument near character 14

View 1 Replies View Related

Programming :: Bash Array Add Function Example Using Indirect Array Reference As Function Argument?

Jun 20, 2010

I looked on the net for such function or example and didin't find anything, thus after having made one i guess it would be legitimate to drop it to see what others thinks of it.

#!/bin/bash
addelementtoarray()
{
local arrayname=$1

[code]....

View 10 Replies View Related

Programming :: Bash/Perl Script - Provide List Of Hosts To Choose From And Ssh To Chosen Host?

Apr 6, 2010

I'm not sure if this is best done in Perl or Bash. I'm thinking surely someone else has created something close to what I'm looking for. The results of the script would be that someone would kick off "linux_hosts.sh" r whatever you want to call it, then a top "folder" of options (with hosts contained within each of these top menu choices), then, based on which number corresponds to that top level, they're presented with a set of linux hosts that are relevant to that top level name. Example:

$ linux_hosts.sh
1. VMware hosts 4. Private Domain
2. ESX servers 5. Red Hat boxes

[code]...

View 4 Replies View Related

General :: Find Argument List Too Long?

May 12, 2011

I want to search in many many files for a string.

I used find /archive/* -print0 | xargs -0 grep 'robert' -sl

Is there a simple method to do it ?

View 2 Replies View Related

Ubuntu :: Large Number Of Files To Count - Argument List Too Long

May 28, 2011

I have the standard problem of trying to count a large number of files in a directory (>100k)

I have tried: ls ~/user/images/* -l | wc -l and find ~/user/images/* -maxdepth 1 -type f | wc -l

In both cases, I get the argument list too long error message.

I have tried using xargs but I can't seem to get it to work right.

The command

returns a valid answer but it includes all the subdirectories in the file count.

View 4 Replies View Related

General :: Bash - Shell Utils: Convert A List Of Hex To List Of Decimals?

Dec 27, 2010

How can I convert a file with a lot hex numbers into the decimal?

Example: file1
0x59999
0x5acdc
0xffeff

I want to start $ cat file1 | util | cat >file2 and get file2 with smth like

[Code]...

View 3 Replies View Related

General :: Bash Script Command - Argument Disappears

Oct 25, 2010

I call my script with ./script -e arg2. However, $@ only shows me arg2. Surprisingly, if I use ./script -s arg2, $@ shows me both arguments. What's going on?

View 4 Replies View Related

Programming :: BASH Sort List By End Of Line To X Position In Each Line?

Aug 18, 2010

I'm trying to make another file annotation script a little speedier than it has been by the up-until-now proven method of checking the last four characters in a filename before the "dot" (eg .jpg, .psd) against a list of known IPTC categories and Exiv2 command files. It occurred to me that if one script generated a list of files in directory foo, and the same or another script sorted that list by that four-letter tag,then that list could be used(instead of a for/do/done loop on the real files in the folder) by the command-file-matching script to "vomit out" which annotator file would go with file nastynewfile.jpg, f'r'instance. The script I had been using for this task looks like this:

Code:

while read 'line';
do
sp=$(echo $line)
vc=$(echo $sp | cut -d"," -f1)
cv=$(echo $sp | cut -d"," -f2)

[code]....

Where I seem to be stuck is with how to sort the lines in templist, which may be any number of different lengths, from back to front. sort -k looked promising, except it seems only to work the other way round. I thought of invoking a

Code:

q=$(expr length $line); echo $q
n=$[q-8]; echo $n

kind of thing, but that presented the problems of how to sort by those, how to tell sort where to find them (grep?) and how to "stitch them back in" to the original list, which is what I want to sort in the first place.

View 14 Replies View Related

General :: "Argument List Too Long" - Deleting Files Based On Grep?

Jan 28, 2011

I've got a directory with thousands of files and I want to delete those that contain specific text.When I try:Code: ls | grep -l "specific text" * | xargs rm I get the error: Code: /bin/grep: Argument list too long Is there an easy way to get around this without having to move files into seperate folders and processing them in batches? I found an article on getting around this problem, but I'm kind of new to Linux and don't know how to apply this to my specific problem.

View 3 Replies View Related

Ubuntu :: Write A Base Script Which Will Divide An Argument By 10 And Then Use That Argument In Another Program?

Feb 23, 2010

I'm trying to write a base script which will divide an argument by 10 and then use that argument in another program. Since my argument can be a floating point number, I used bc to accomplish this. Here's an example of a simplified version of what I have so far:

<code>NUM=$(echo "scale=25;$1/10" | bc)
#make sure the first argument was formatted correctly
if [ $? -ne 0 ]

[code]...

View 4 Replies View Related

Programming :: Argument Relations In CGI Script

Feb 15, 2010

I have made fallowing script for CGI scripting learning purpose:

Code:
#!/bin/sh
echo "Content-type: text/html"
echo
CMD='echo "$QUERY_STRING" | sed -n 's/^.*cmd=([^&]*).*$/1/p' | sed "s/%20/ /g" '
echo "<html>"
echo "<head><title>Hello CGI</title></head>"
echo "<body>" .....
echo "<input type=radio name=cmd value=ifconfig checked> ifconfig <br>"
echo "<input type=radio name=cmd value=uname> uname -a <br>"

This script works fine, but actually I quite don't understand it's inner working about those radio buttons.

View 1 Replies View Related

Programming :: Insert $2 Argument Until The End To Variable?

May 17, 2011

how to insert $2 argument until the end to variable?For example:

>> cucu.csh user "long long message "
$1 = user
$2 = "long long message "

View 10 Replies View Related

Programming :: List 4 Names From Users List And Output Them To Fbusers In Numbered Ascending Order?

Feb 2, 2010

How would I list 4 users ID numbered 10, 11, 12 and 13 from my users list and output them to a file busers where their names are numbered by ascending order? How would I accomplish that on a one line command?

View 4 Replies View Related

Programming :: Making A 1 Command Line Argument?

Jun 8, 2010

I need to write a script that will take 1 command line argument. The argument will be a username. The script will determine if the user exists on the system and will print an error if it does not. If the user does exist it will determine if the user is currently logged in, if the user is not logged in it will determine the last time the user logged in and display the file in the users home directory that was most recently modified.

View 2 Replies View Related

Programming :: Passing The Char * Vector Argument?

Jun 19, 2010

I am trying to simulate a shell. So what I do is checking of having the parameters from standard input, suc as "/bin/ls -l /home/france/Documents", and then passing them to function execute, which at some point calls execvp(argv[0],argv)The problem is that I don't succeed in using these arguments, while if I call execvp(paramList[0],paramList) it works!!!! Where paramList is exactly what I would put on standard input, but defined statically.

Code:

#include<unistd.h>
#include<stdio.h>
#include<stdlib.h>
#include<string.h>

[code].....

View 2 Replies View Related

Programming :: C - User To Input The Name Of A File As An Argument

Aug 5, 2010

Write a program that requires the user to input the name of a file as an argument. If the user fails to include one argument it should make use of a thread that handles a signal. The signal handler should tells the user Incorrect number of arguments and then calls the terminate signal on the process.

If the numbers of arguments are correct then the program should allocate memory space to the file (5MB) and create a child process that requests the user for a character that it should send to the parent. The child should keep request for data until the user keys in the character O. During each request it should pause for 10 seconds, send the character to the parent and then requesting again for another character.

The parent should get the character from the child. Do not make the parent wait for the child to finish requesting for data. Make use of pipes to facilitate communication between the parent and the child. A second child should be created to read and display data from the file. Make use of any appropriate Inter Process Communication technique to ensure that the second child and the parent do not access the file simultaneously (Mutual exclusion).

View 5 Replies View Related

Programming :: CreateProcess() In C \ Specify The Location Of The File As An Argument?

Aug 31, 2010

am coding a chat program in C (win32), where I need both the client and the server to communicate, without waiting for a reply from the other side, like the way we chat in any messenger. Is there any way of accomplishing it? I tried out CreateProcess() function, but am not clear how to specify the location of the file as an argument.If there are better techniques than CreateProcess(), then

View 13 Replies View Related

Programming :: Shell: Give A Range Argument To 'for'

Feb 20, 2010

Feel free to just link to another thread where this is (pre)solved; I can't search the forum for the word "for," because it's too short (or maybe the search engine dislikes prepositions).

Is there a way to give the 'for' command a range? Here's what I mean:

Code:
#for i in (1-5); do echo $i; done
Certainly, meat space user; I understand exactly what you're thinking.
1
2
3
4
5
True, I realize I could use

Code:
COUNT=1 ; while [ $COUNT -lt 6 ]...

...but if I can avoid the extra preparatory step I'd prefer to do so.

View 2 Replies View Related

Programming :: Downloading A List Of Files From A Remote Server Using A List?

Feb 10, 2009

I am trying to get this script to work. The purpose is to download a list of modules from the slax.org the list consist of a list of module numbers. What I am trying to do is Download the file or the file name corresponding to the number in the list.the list is comma delimited. this is what I have done so far and I am a stand still.

#!/bin/sh
# Wget script to retrieve modules from slax.org modules
#
# ----Begin of user defined values -----
# Path to wget

[code].....

View 7 Replies View Related

Programming :: Pass Complicated Commands As Argument To Another Script?

Apr 21, 2010

I am attempting to script some tasks I have to do, but I have no control over one of the scripts I have to use... and they output all kinds of useless things on the screen. My goal is simple: Capture all output from their scripts, and create a progress line that only shows the most recent output from their stuff. So, here was my first solution; a file I called "spin":

Code:
#!/bin/bash
spinX(){
PROC=$1
STRT='date "+%s"'
while [ -d /proc/$PROC ];do
last3=" 'getLine $2' "

To use it, you pass it a process ID and a file that contains the output from that process. As the process continues, a kurby dances on the screen (To let you know that the process has not hanged), and the tail of the output is shown (To let you know what it is doing). When the process ends, the kurby stops dancing and the time it took is displayed.

And here is the file I call "noise":
Code:
#!/bin/bash
while [ i -lt 100 ];do
i=1
echo "Look at me count!$"
sleep 1
let "i=$i+1"
done

This does nothing but create random output, for testing. It counts from 1 to 99 on the screen. To run my test, I do the following:
Code:
(noise) &>tmp.txt & spin $! tmp.txt

It works relatively well, but it is messy. I don't like creating a temp file, and I don't like the messy syntax for calling my program. I decided that I would rather move everything into the spin program, to make using it less messy:
Code:
#Spin Psuedo code
#$1 = command I am about to run
(exec $1) &>tmp.txt & spinX $! tmp.txt

By executing the process inside of the spin code, I can get rid of the tmp file later on without changing a lot of scripts (Or move it, or whatever). I can also call it by passing the command to the script, which I find more elegant.

So here is what I would like to know:
1) If possible, I would love to get rid of the tmp file all together, and store the most recent line of output from script 1 into a variable that script 2 can print out instead... is it possible?
2) How can I run a random command that is passed as an argument? Basic ones work fine, but anything with a pipe fails me.

Example of a script:
Code:
#!/bin/bash
#myEcho.sh
echo;echo "Recieved command: ";echo $1;echo;
echo "Attempting to run command: ";echo
exec $1

Example code for passing commands to script:
> myEcho.sh "ls -al" #works
> myEcho.sh 'ls -al' #works
> myEcho.sh "ls -al|grep *.sh" #fail
# Output:
#ls: invalid option -- |
#Try 'ls --help' for more information.
> myEcho.sh "ls -al|grep "*.sh"" #fail
# Output:
#ls: invalid option -- |
#Try ls --help' for more information.
> myEcho.sh 'ls -al|grep *.sh' #fail
# Output:
#ls: invalid option -- |
#Try 'ls --help' for more information.

View 8 Replies View Related

Programming :: Ssh Remote Command Preserve Quoted Argument?

Sep 17, 2009

I have a python script on one server (serv_one) and I am trying to execute it remotely from another (serv_two). The python script takes an argument with spaces. If I execute it locally:

Code:

foo@serv_one> script.py --o "arg one"
"arg one" is preserved, of course. ( argv = [ '--o', 'arg one' ] )

However, when I execute it remotely:

Code:

foo@serv_two> ssh ... foo@serv_one script.py --o "arg one"

the double quotes around "arg one" are dismissed ( argv = [ '--o', 'arg', 'one' ]. I've tried many combinations of single quotes/double quotes/backslashes, etc, to no avail. One hack solution I came up with, since I have the flexibility, was to replace all spaces in the quoted argument with a character that would be invalid in the argument (before the ssh call), and replace those with spaces in script.py. I would probably like to avoid this solution if at all possible.

View 7 Replies View Related

Ubuntu :: Add Additional Option To Only List Files That End With X?

Apr 2, 2011

I know i can use ls comand to list files in folders other than current working directory like this:

Code:
ls /home/user

But where do i add additional option to only list files that end with x?

View 9 Replies View Related

Programming :: C++ Program Calling A Fortran Subroutine With A Function In The Argument?

Mar 9, 2011

I have a new problem; i want to call a subroutine's fortran which have a function in the argument and the compilation ran properly, but when i execute the program this shows me an "Segmentation fault". This is my c++ program:

Code: //Main.cpp
#include <stdio.h>
#include <iostream>

[code]....

View 2 Replies View Related







Copyrights 2005-15 www.BigResource.com, All rights reserved