Questions about shell scripts, executable files that are interpreted by a shell (bash, zsh, etc.).

learn more… | top users | synonyms (1)

0
votes
1answer
311 views

How does “options” in shell scripting work?

I found some code in one of the answers here and accommodated it to my needs but now I have two questions: Q1: how can I display the options text after the code in case statement finishes? So the ...
3
votes
2answers
314 views

rename randomly files on a USB device

I would like to rename all of my files of my USB device randomly. Indeed, in my car, my tuner has not the random function. I think I can do it with PHP ... but I'm pretty sure it is possible to do ...
1
vote
1answer
169 views

Making multiple calls to a program via a bash shell script

Suppose that I have a program make_ndx that outputs via the -o switch. I would like to call myprogram from a bash shell script and output two files, out1.ndx and out2.ndx. (myprogram takes a string ...
1
vote
1answer
727 views

Do shells support recursion?

I'm trying to write recursive functions in my shell scripts. Consider the following code: function printA { if [[ "$1" = 0 ]]; then return else echo "a$(printA $(("$1" - 1)))" ...
9
votes
3answers
12k views

Shell script fails: Syntax error: “(” unexpected

I've been working on a script that automates setting up a development environment for Raspberry Pi development (step by step details that work are here). The script is linked in that article but ...
2
votes
2answers
314 views

Executing zsh rehash after build

I have a build script that can change what binaries are in my $PATH (it doesn't edit $PATH itself, but it adds/deletes files to folders that are already in $PATH). zsh's autocompletion doesn't update ...
2
votes
1answer
132 views

How to have find only search for files in changed directories?

Currently I'm repeatedly doing a 'find' that's too slow. I'm searching for non-hidden executable files within "$root", excluding "$root/bin": find "$root" -type f -perm -o+x -not -path "$root/bin/*" ...
2
votes
1answer
383 views

Extended file globbing not working with cat inside bash script

When, in my terminal, I type cat ~/my/+(a|b)/doc It reads ok from both ~/my/a/doc and ~/my/b/doc, but when I put that command in a bash script: #!/bin/bash cat ~/my/'+(a|b)'/doc I get the error: ...
7
votes
1answer
507 views

Bash script doesn't read input

I have a script that is suppose to run a command in the background, and it does that. The problem is that when the script comes upon a read command, it doesn't pause and accept input. Here it is: ...
2
votes
3answers
674 views

Copy/backup all dirs containing files matching a regexp

I would like to do a backup where I recursively go through a dir structure and only get directories with files whose names matching a particular regexp. I would like to keep the directory structure, ...
4
votes
1answer
762 views

Validate AIX Password for root from script

Looking for a way in a shell script to validate the password for for root on an (AIX) matches a standardized plain text password. This query is similar to another one on this site. I have access to ...
4
votes
2answers
940 views

bash myscript.sh runs in bash, but the first line is #!/usr/bin/sh

I have a script similar following one: #!/usr/bin/sh var="ABC" if [ $var == "ABC" ] then echo True else echo False fi Above code does not work in Solaris Sparc and Solaris X64. It is showing ...
2
votes
4answers
22k views

Adding two numbers using expr

I'm learning Shell scripting for a diploma in IT I'm currently doing. I'm trying to write a small script that adds two numbers as shown as in one of the tutorials we were given. echo "Enter two ...
6
votes
1answer
711 views

Are dash, ash and sh script 100% compatible?

I wanted to know whether scripts written for dash, ash, and sh are 100% compatible? Are there any added features to dash or ash, or syntax change? From what I heard, ash is a direct descendant of ...
2
votes
2answers
862 views

When sh is a symlink to bash or dash, bash limits itself to POSIX-compliance, so it should be 100% compatible with sh?

From Difference between bash and sh: ABck to the question: If you have /bin/sh as a link to bash, then bash will not behave the same when called as /bin/sh as it does when called as /bin/bash. ...
6
votes
1answer
256 views

How to find out whether a shell script is written in bash or sh

How can I find out whether a script is written in bash or sh? The first line of the script is not helpful here, since on Linux, bash scripts have this line: #!bin/sh Actually, there are many ...
2
votes
1answer
1k views

Can I run Bash scripts in FreeBSD without modifying them?

Correct me if I'm wrong: "sh" script != "bash" script Linux script are written in Bash Bash script usually #!/bin/sh In GNU/Linux, /bin/sh is Bash In FreeBSD, /bin/sh is not bash, it's the true sh ...
5
votes
3answers
6k views

ssh input from text file

These two question is driving me crazy and I don't have good expertise of ssh. (but I suspect it is to do with redirection only) The questions are, You want to pass multiple lines of input from a ...
5
votes
2answers
2k views

assign shortcut key to run a script

I've written a script to change the brightness of my screen. It's useful when I am working on text mode and shortcut keys of my keyboard to change brightness doesn't work. Is it possible to run this ...
3
votes
3answers
2k views

Shell Script to Execute Shell Script to All Subdirectories

I am making a script to simplify my daily tasks. Everyday, I have to grep for a few things inside a company server. It was okay, however, now, they have segregated each object into sub directories. I ...
1
vote
1answer
335 views

Identify remote windows server from shell script

I need a way to Identify a windows SBS server, I have a script that mounts a file share on a SBS server, I need the script to positivity identify the server before mounting. It doesn't need to be ...
6
votes
2answers
3k views

Why does `exec 2>&1` fail in this bourne shell script?

I am porting an old ksh script to Bourne shell. The old ksh script contains the following code: #!/bin/sh tmpLog=/var/tmp/logfile.$$ exec 1> $tmpLog exec 2>&1 eval $* another_command_1 ...
2
votes
1answer
429 views

Assigning command output to variable gives strange results

My script looks like this: #!/bin/sh PROJECT_DIR=$(cd -P -- "$(dirname -- "$0")" && pwd -P) COMMANDS_CODE=$(php $PROJECT_DIR/bin/console generate:code) echo $COMMANDS_CODE The output has ...
1
vote
2answers
647 views

On the command line, can I redirect output to a file WITHOUT >, >>, or | operators?

I am attempting to run a command on a CentOS virtual machine, and the API that I am using to run this command does not seem to allow the >, >>, or | operators. Also, I must use fully qualified paths ...
0
votes
0answers
2k views

bad magic number

I have a script which I need to execute. The script file is push.sh. Below are the commands that I am using: dragan@dragan-Lenovo-G570:~/liquibase/liquibase$ chmod +x push.sh ...
6
votes
4answers
8k views

printing colored text using echo

I know that for printing a colored text using echo, for example red color, the code is: echo -e "\e[1;31m This is red text \e[0m" and I know that in this example, 31 is code of red color and the ...
14
votes
4answers
12k views

How to introduce timeout for shell scripting?

I want to run a shell script that got a loop in it and it can go for ever which I do not want to happen. So I need to introduce a timeout for the whole script. How can I introduce a timeout for the ...
3
votes
2answers
1k views

How to solve sudo: unable to execute /bin/ls: Argument list too long

When I run this command from php sudo -u db2inst1 ls -t /var/lib/edumate/bdrs/*/*/daily/*NODE* | sort -r I receive sudo: unable to execute /bin/ls: Argument list too long ls lists all daily backup ...
17
votes
1answer
447 views

Is there a standard command that always exits with a failure?

I want to test my script with a command that fails. I could use an existing command with bad arguments. I could also write a simple script that immediately exits with a failure. Both of these are easy ...
2
votes
0answers
349 views

Validate Password for user account from shell script

Application is for a multiple server standardization script Looking for a way in a shell script to check if the password for an OS account (AIX) matches a standardized plain text password. The ...
21
votes
3answers
3k views

How to do nothing forever in an elegant way?

I have a program which produces useful information on stdout but also reads from stdin. I want to redirect its standard output to a file without providing anything on standard input. So far, so good: ...
4
votes
1answer
171 views

Discard stdout of a command for t seconds

I am working on some batch scripts involving the following: Run some non-terminating sub-processes (asynchronously) Wait for t seconds Perform other task X for some time Terminate subprocesses ...
9
votes
1answer
2k views

Are there naming conventions for variables in shell scripts?

Most languages have naming conventions for variables, the most common style I see in shell scripts is MY_VARIABLE=foo. Is this the convention or is it only for global variables? What about variables ...
3
votes
3answers
6k views

Automating textual input from a bash script without using EOF

I'm running Ubuntu Linux. Suppose there is a program called myprogram. This program prompts the user for input; specifically, the user must type an integer when prompted and press Enter. I would ...
3
votes
2answers
608 views

is there any command like “wall” that runs a “command” in all terminals

as you know "wall" command sends a message to all terminals: wall message now my question is this: is there any command that can send a "command" to be run in all terminals? for example sending ...
16
votes
2answers
280 views

Shell function definition: why is there a space after the opening brace?

You probably know of that fork bomb: :(){ :|:&};: #WARNING: harmful code I wonder why it is necessary, for it to parse, to include a space after the opening curly brace.
5
votes
1answer
996 views

A couple arithmetic related commands, Dash, POSIX shell, sh, Increment

When pre/post incrementing a variable, in POSIX Shell, what is the difference between these two examples. They seem like they would have the same consequences, but would they be used differently? ...
2
votes
1answer
1k views

How can I set environment variable permanently through shell script?

Let's say I have a script: #!/bin/bash echo $1 if [[ ! $1 ]];then echo "True" fi export ABC="/home/aashish" ABC is not available after the execution of this script. How can I make that variable ...
3
votes
1answer
2k views

Shell script hangs on mail command

I'm finding that a call to the mail command is causing a script to suspend without error. To close the script I have to ctrl-c or issue a kill command on the process id. The pertinent section of ...
1
vote
3answers
243 views

Concise way to output to file if argument is given, to stdout otherwise

I'd like my script to output to stdout unless it gets a filename as an argument. An obvious way is like so: if [ -e "$1" ]; then command_with_output >$1 else command_with_output fi It's ...
4
votes
1answer
4k views

shell backup script, missing `]`

I'm putting together a simple backup script that will tar contents of a folder, then move that file to a backup server. The script makes sure that the tar file exists and is not zero bytes before ...
5
votes
2answers
860 views

How to tweet using terminal?

I would like to tweet a message using terminal. I tried something like: curl -u 'TwitterUsername':'TwitterPassword' -d status=”Your Message Here” https://twitter.com/statuses/update.xml but seems ...
2
votes
1answer
83 views

Restoring an option at the end of a function in zsh

I'm writing a zsh shell function (as opposed to a script) where I would really like the extended_glob option to be enabled. But since the function runs in the caller's context, I don't want to clobber ...
0
votes
2answers
682 views

Re-assigning (specifically, incrementing) a variable in a bash script [duplicate]

Possible Duplicate: How can I do command line integer & float calculations, in bash, or any language available? I would like to simply re-assign a variable (to be specific, increment it ...
2
votes
1answer
304 views

Prompting for input in post-install script in dpkg

I am writing a debian package and need to prompt the user for some textual details(default password, etc), as well as some one-of-many choices("Pick one of the following: foo, bar"). Will shell ...
3
votes
1answer
285 views

Script for emulating Windows [Win]+[Arrow] keyboard shortcut

I am running Fedora 14. I would like to (at least partially) emulate the behaviour of Windows when you hit Win+Arrow Key. That is, I would like it to "snap" to the left/right sides of the screen. I ...
5
votes
2answers
388 views

Automate workflow in shell

Coming from GUI interfaces I've come to finally understand the power of having everything piped in text, but I don't really know how to use all that power yet. I realized the workflow for a ...
9
votes
3answers
2k views

How to sort the string which combined with string + numeric using bash script?

This is the data what I want to sort. But sort treats the numeric to string, the data it no sorted as I expected. /home/files/profile1 /home/files/profile10 /home/files/profile11 ...
1
vote
2answers
1k views

Show command executed along with output in log file

Is there a quick and dirty way to not only log the output of a shell file but the commands used inside as well? For example: whoami > who.dmp would output a file that contained something like: ...
6
votes
4answers
2k views

How to create a testcolor.sh like the following screenshot?

I found this image on the internet, but don't know how was it made, Can anyone provide a sample on that? I just would like to have a color table as well.