bash

LINES and COLUMNS environmental variables lost in a script

Consider the following: me@mine:~$ cat a.sh #!/bin/bash echo "Lines: " $LINES echo "Columns: " $COLUMNS me@mine:~$ ./a.sh Lines: Columns: me@mine:~$ echo "Lines: " $LINES Lines: 52 me@mine:~$ echo "Columns: " $COLUMNS Columns: 157 me@mine:~$ The variables $LINES and $COLUMNS are shell variables, not environmental variables, and ...

In bash shell script how do I convert a string to an number

Hey I would like to convert a string to a number x="0.80" #I would like to convert x to 0.80 to compare like such: if[ $x -gt 0.70 ]; then echo $x >> you_made_it.txt fi Right now I get the error integer expression expected because I am trying to compare a string. thanks ...

How do I find out what options git-diff uses when it invokes less?

I want to reproduce the pager behavior that git-diff uses but I don't know how. Is there a way I could find out what options it uses with less? I already tried this: strings "$(dirname $(which git-diff))/*" | grep 'less ' And this (while less was running): ps aux | grep less <= Didn't show me which options it was using. I'm on Darwin....

Bash scripting on Android

Has anybody tried bash scripting on android? I tried to write a simple script on Android's bash shell through adb. I tried the following script which works for me: #sh1 x="hello" echo "$x" But when I do: #sh1 x="hello" if [ -n "$X" ]; then echo "hi" fi The error says [ -n not found! Why do I get this error and is there a work ...

How to GZip every file separately

Easy and fast question, I just don't want to have all of them in a big tar :-) ...

choosing even-numbered rows from a file

How do I choose even numbered rows of a file? I wish to select rows #2, 4, 6, etc. from a file that contains data. Can anyone help me with this? ...

How do I change the shell for php's exec()

Hey, I want to use php's exec() function on an ubuntu server. The problem is, I alway get an error, that the command is not found. For example using exec("echo 123"); prints sh: /echo: not found To me, it looks like php is using the sh shell, when I want to be using bash. I tried changing the shell for www-data in /etc/passwd,...

Bash Shell Script error: syntax error near unexpected token '{

Below is the snippet of code that keeps giving me the problem. Could someone explain to me why my code isn't working. # Shell Version of Login Menu Administrator () { clear ./Administrator.sh } # ------ Student User Menu ------ Student_Menu() { clear ./studentMenu.sh } # ------ Borrow Menu ------ Borrow_Menu() { c...

Bash script on Solaris, using ":" on an array does not always work

I have a strange issue with array manipulation within a bash script on Solaris. I am using the syntax ${varName[@]:index} to obtain all of the elements in array varname after the specified index. However, if there is only one element after the specified index, nothing is returned. This can be easily demonstrated by example: #!/bin/bash...

grep-ing multiple files

I want to grep multiple files in a directory and collect the output of each grep in a separate file ..So if I grep 20 files, I should get 20 output-files which contain the searched item. Can anybody help me with this? Thanks. ...

How do I fix "bash: perl myscript.pl: command not found"?

Maybe it's dumbest question in the world, but I seriously have problems with it and could use help. I am trying to run perl script on linux. It's a simple text editing script, nothing fancy. I googled for it and I found that I had to chmod +x it and then just run myscript.pl in the console. Since it's supposed to modify a text file I did...

Bash alias query

How can I turn the following command into a bash alias? find . -name '*.php' | xargs grep --color -n 'search term' Where I can specify the file extension and 'search term' is obviously the search term :) So what I want to do is: searchFiles 'php' 'search term' How do I pass the input into the alias? Should I just create a bash sc...

problem with redirecting output

I'm writing a script that selects rows from files in a directory which contain patterns $f1, $f2 and $f3 and storing the lines that contain the pattern in a file I want to call as $file_$pattern.xls, for example file1_2.54 Ghz.xls. #!/bin/bash #my_script.sh to summarize p-state values f1="2.54 Ghz" f2="1.60 Ghz" f3="800 Mhz" for f in...

cygwin tab completion

how can a complete novice such as myself set up her cygwin to have tab completion? edit: I do have it automatically. but It does not seem to complete paths. how do I set it up to complete paths? thanks! ...

arrow key via stdin

Hi everybody, I'm trying to send an arrow key via the stdin to the bash: cat | /bin/bash then i am typing "echo hi" => "hi" appears on the console (of course without the quotes) then i press the arrow key up => ^[[A command not found appears Is it possible to send an arrow key to an program via the stdin ? The reason why i am asking...

Is there a better way to erase a line than echo " "?

I am wanting to erase several (let's say 10) lines on the screen using bash. I know this can be done by: for x in `seq 1 10`; do echo " " done but there must be a better way. Something like: echo -n10 --blank or echo -n10 space(80) or something similar. Any ideas? ...

How can I assign the output of a function to a variable using bash?

I have a bash function that produces some output: function scan { echo "output" } How can I assign this output to a variable? ie. VAR=scan (of course this doesn't work - it makes VAR equal the string "scan") ...

Looking for book on Bash scripting

I'd like to brush up on my knowledge of Shell scripting with Bash for a job interview Monday. What would the preferred book be for someone with an existing knowledge looking to review the topic? ...

GUI Using Shell Batch File

I'm now going to develop a program that will generate Shell Batch Files(*.sh), but I want to know some things: It's possible to show GUIs using they? How to do this? ...

Portable way to get file size (in bytes) in shell?

On Linux, I use stat --format="%s" FILE, but Solaris I have access to doesn't have stat command. What should I use then? I'm writing Bash scripts, and can't really install any new software on the system. I've considered already using: perl -e '@x=stat(shift);print $x[7]' FILE or even: ls -nl FILE | awk '{print $5}' But neither of...