0
votes
1answer
24 views

How to evaluate a variable length in shell script?

I want to write a shell script, in which it will call different command according to the variable length. But I didn't figure it out yet. My unwork script is here: for i in n5 n25 if ${#i} == 2; ...
8
votes
6answers
357 views

How can I test if a variable is empty or contains only spaces?

The following bash syntax verifies if param isn't empty: [[ ! -z $param ]] For example: param="" [[ ! -z $param ]] && echo "I am not zero" No output and its fine. But when param ...
4
votes
1answer
108 views

Proper way to distribute shell scripts

What is the most proper way to distribute shell scripts, if behaviours of shells can be modified by set and thus are unpredictable? For example, rm *.txt wouldn't be executed as expected on the ...
2
votes
1answer
35 views

Arrow key/Enter menu

I need help finding out how to possibly create a menu in a shell script that will display 3 options that a user will use the arrows keys to move the highlight cursor and press enter to select one. If ...
2
votes
1answer
41 views

How can I get this script file's functions to load without having to source it every time? “command not found” (Bash/scripting basics)

How can I get this script file's functions to load without having to source it every time? I created a file foo with script functions I'd like to run. It's in /usr/bin, which is in the PATH. File ...
0
votes
1answer
62 views

Bash script question - skip enter key press [duplicate]

Here is a portion of my script: read main_menu case "$main_menu" in "0" ) exit ;; "1" ) cp /etc/bamt/cgminer.conf.X11 /etc/bamt/cgminer.conf; sudo mine restart; ...
1
vote
1answer
36 views

Bundling of dependencies with shell scripts

Shell scripts often have to depend on tools that may not be installed on the users' computer. To circumvent this problem, many scripts have multiple fallbacks. IMO doing such things only leads to ...
2
votes
2answers
109 views

How to force watch to run under bash

The problem is that when watch is executed it runs sh and I get this error: sh: 1: func1: not found here is the code: #!/bin/bash func1(){ echo $1 } export -f func1 watch func1
1
vote
1answer
23 views

How to slice a text file into several files of 100 lines each? [duplicate]

My question might be quite unclear here. I have a giant text file with values that looks like this 0.00601233 0.000139403 0.000133679 0.000139497 0.000141683 0.000141888 0.000138646 0.000133465 ...
3
votes
1answer
30 views

Why does the read command not take interactive options when run by sh?

I want to download a provisioning script that reads some configuration parameters via read, and execute it: curl http://example.com/provisioning.sh | sh The problem is, that the read command in the ...
2
votes
1answer
28 views

setenv not working in tcsh

I am trying to install a program on my brand-new CentOs. The installation requires setenv, which apparently does not work, not even in the tcsh shell. Can anyone give me some advice? [Anna@anna ...
4
votes
4answers
268 views

what does $* mean in shell [duplicate]

What does $* mean in shell? I have code two function, run_command and run_test, they are called like this: if [ -n "`echo ${GOAT_COMMANDS} | grep $1`" ]; then run_command $* else run_test $* fi ...
3
votes
1answer
47 views

Using inotify to monitor a directory but not working 100%

I have written a bash script to monitor a particular directory /root/secondfolder/: #!/bin/sh while inotifywait -mr -e close_write "/root/secondfolder/" do echo "close_write" done When I ...
2
votes
1answer
68 views

Accumulate Filename in a Log file using shell script

I have files with their names as ABC_-_123321.20140505_-_161500.CSV ABC_-_654145.20140506_-_135020.CSV String_-_SerialID.Date_-_Time.CSV StartDate, StartTime, EndDate and EndTime are given as ...
1
vote
2answers
54 views

sh + how to use array in sh script in order to print all values in array

I want to use arrays in my sh script. My target is to create an array with the values a b c and print all values in the array. I succeeded to print each array, but I failed to print all values in ...
2
votes
1answer
43 views

Displays and their relative position in a shell script

I want to get information about the displays, something like xrandr, but with more info. I want to know their position. So if I have two or more displays connected I want to know how they are ...
2
votes
1answer
37 views

Extracting lines around keys from a file

I have a large file with around 15 million lines. The odd lines contains the keys (but not only the keys) and the even lines are the data. That is, the file is something like: WRTZ Tyrosine ...
0
votes
2answers
32 views

list files and store it in variables

im new with shell programming. my goal is to give the user a selection which file should be run. i catch all available scripts in one var with: var=$(find script*) so far so good.. this is the ...
3
votes
4answers
157 views

How to cut everthing until a specific word / after a find in a script

Hello I try to get the output of files from today wich contains ERROR. I use this to find the files I want: find /home/user/logfilesError/ -maxdepth 1 -type f -name "gandalf_*"\ -daystart -mtime ...
1
vote
3answers
422 views

Difference between ls -l and ll?

I'm relatively new to programming as a whole and some tutorials have been telling me to use ls -l to look at files in a directory and others have been saying ll. I know that ls is a short list, but ...
0
votes
1answer
117 views

How do I cat a command file?

I have the output of the crontab -l stored in a file (crontab_file) with no extension. But whenever I try to cat it, I get errors saying command not found for multiple line of the file. Here is the ...
28
votes
3answers
2k views

What does `{ { (exit 1); exit 1; }; }` mean?

I quoted the next code snippet from config.status generated by configure. if test ! -f "$as_myself"; then { { echo "$as_me:$LINENO: error: cannot find myself; rerun with an absolute path" >&5 ...
2
votes
1answer
73 views

Why is my tar in a script behaving different than using tar manually

I'm writing a backup script for my email and cloud service. For simplicity, I only posted the mail-backup part here. Basically, I have a Host-Machine with some Virtual Boxes running in it. These ...
0
votes
1answer
38 views

Scripting error after bc command

I am trying to execute script contains the following: #!/bin/bash USED=`free -m | more | grep -v total | head -1 | cut -d':' -f2 | cut -d' ' -f18` CACHE=`free -m | more | grep -v Swap | tail -1 | cut ...
0
votes
0answers
41 views

Specific Jar file doesn't run on startup

I want to run a jar at startup, so I asked a question here. I was given a few suggestions, so I started from trying to create a script file and desktop file. I created a script file and desktop file ...
2
votes
2answers
132 views

How to get previous year and previous month in solaris 8

How to get previous year and previous month in solaris 8? I have tried below command but none of them is correct: date +'%m' -d 'last month' date +'%Y' -d 'last year'
5
votes
2answers
124 views

How exactly does `if $cmd ; then $cmd ; fi` differ from `$cmd && $cmd`?

In an answer to another very good question I made the following assertion: According to my reading of the POSIX specs, the use of one or the other makes no difference from a parsing standpoint. ...
8
votes
4answers
808 views

Bash syntax error when “else” follows an empty “then” clause

Why would following script not execute, but give a syntax error of else: LOGS3_DIR=~/logs if [ -d "$LOGS3_DIR" ]; then cd cd "$LOGS3_DIR" echo "$LOGS3_DIR" for filename in `find "." -mtime 1 ...
2
votes
3answers
106 views

grep on a Java Method

Lets say I have a java class called DirectAction some of the methods in the class have the word "action" or "Action" What is the grep command to get the names of all the methods who have "Action" or ...
5
votes
3answers
1k views

Prompt user to login as root when running a shell script

The problem I am getting is, when I enter the command, su - root at the beginning of my shell script file, it prompts the user to enter the password and then does NOT continue with the rest of the ...
5
votes
2answers
136 views

What does ${3#?} do?

I have a script with the following variable assignment: TEST_VARIABLE=${3#?} What does the ${3#?} do?
1
vote
2answers
114 views

Run jar on startup in all *nix based systems

I have a jar file which I need to run at startup in all distros of Linux. My previous question here, gave me an idea a rough idea on X-servers. Since I wasn't able to perform startup, I moved on to ...
2
votes
1answer
90 views

How to create an executable bash script for these commands?

I wish to create an executable bash script that will run the following commands as root, that is, using sudo su iptables-save | awk '/^[*]/ { print $1 } /^:[A-Z]+ [^-]/ { print ...
18
votes
2answers
665 views

Why does my shell script choke on whitespace or other special characters?

Or, an introductory guide to robust filename handling and other string passing in shell scripts. I wrote a shell script which works well most of the time. But it chokes on some inputs (e.g. on some ...
1
vote
2answers
142 views

How to show specific lines from specific columns of a file

First off, I'm not allowed awk, sed or perl. For my assignment I was given a file of employee list: Marketing Ranjit Singh FULLEagles Dean Johnson Marketing Ken Whillans FULLEagles ...
1
vote
1answer
46 views

Use a bash function in a pipelined command

I have a command similar to: ... | sort -u -V. Since some versions of sort do not support the -V flag, I thought it would be great if I made a function that conditionally adds the flag. But, it seems ...
1
vote
1answer
94 views

Is there a GUI debugger for shell scripts

Debugging bash scripts on command line is complicated. Is there a good GUI based debugger available for debugging bash scripts?
1
vote
0answers
42 views

Why below script is not able to find and delete files [closed]

Why below find command does not find and delete files ? I am launching it like this ./script.sh 1 MYFOLDER days_period=$1 myuser=$(whoami) folder_prefix=$2 LOGS_DIR=~/$folder_prefix/logs if [ $# ...
2
votes
3answers
91 views

Script needs to read echoed line

So, I need to write a Bourne-shell script, where my script has to work with the line, that was just echoed to stdout - e.g.: echo *something* | myscript.sh [parametres...] This may be a basic ...
1
vote
1answer
26 views

check if genisoimage is succesful

I use a script to convert all VIDEO_TS directories to .ISO. How can I check if genisoimage is actually converting it instead of it failling and converting the next folder? After conversion I have a ...
21
votes
2answers
1k views

What does “${-#*i}” != “$-” mean?

In /etc/profile I see this: for i in /etc/profile.d/*.sh ; do if [ -r "$i" ]; then if [ "${-#*i}" != "$-" ]; then . "$i" else . "$i" >/dev/null 2>&1 ...
1
vote
2answers
103 views

How to properly launch a program and make possible to redirect its running output (stdout and stderr) at a later stage?

The problem is quite simple: I find useful to have the possibility to switch on (and off) the output of some running program in each moment I need. To be more precise I want to be free to redirect ...
5
votes
2answers
264 views

Why doesn't my loop over the output of ls work?

I am trying to feed Directory names into a for loop. My code is as follows: td='/Test/TopDir/' cd "$td" for x in $(ls -d */ | cut -f1 -d'/'); do echo x=$x done The top directory I run this on ...
1
vote
2answers
673 views

How can I run a “grep | grep” command as a string in a bash function?

I'm trying to build a command that pipes the results of one grep command to another grep command in a bash function. Ultimately, I want the command executed to look like this: grep -I -r FooBar ...
0
votes
1answer
32 views

Expansion of *,#,% - What do they mean? [duplicate]

for j in * .* ; do cp $j ../$name-S$i.gid/${j%%. * }$i.${j#*.} done Could someone tell me what this for loop does? What do *, % and # mean? ($name is a path of a directory in which there are ...
1
vote
1answer
128 views

What does “if [ -e $name ]” mean? Where $name is a path to a directory

In the if [ -e $name ], what condition check is -e? $name is a variable of a path to a directory.
4
votes
2answers
351 views

Bash's conditional operator and assignment

Can we use bash's conditional operator with assignment operators after colon? Bash reference manual explains the arithmetic operators as follows. conditional operator expr ? expr : expr assignment ...
4
votes
4answers
99 views

How do I break up a file like split to stdout for piping to a command?

I have a large .sql file full of SELECT statements that contain data I want to insert into my SQL Server database. I'm looking for how I could basically take the file's contents, 100 lines at a time, ...
1
vote
1answer
65 views

Best way to determine piped command to shell script?

Given tree /some/directory | print.sh Is there any way for print.sh to know that "tree -f /some/directory" was called, without trying to parse pid processes?
5
votes
2answers
280 views

Get the actions for a command programmatically

Let's take the git example: $ git<TAB><TAB> git git-import-dscs git-shell git-buildpackage git-import-orig git-upload-archive git-dch git-pbuilder ...