The shell is unix's command-line interface. You can type commands in a shell interactively, or write scripts to automate tasks. Use this tag for questions applying to /bin/sh and most compatible shells (ash, bash, ksh, zsh, …).

learn more… | top users | synonyms (1)

1
vote
1answer
339 views

what's wrong with embedding php scripts inside bash ones?

I was trying to use php inside bash script, but I came across several problems. My first try failed with error about bash not being able to find end of here-document. The minimal version that still ...
4
votes
1answer
124 views

Understanding when background process gets terminated

I have a script which starts a number of background processes and if works fine when called from the cmdline. However the same script is also called during my xsession startup and additionally on ...
17
votes
5answers
1k views

In what situations would a user not let the shell record his command into history?

If I add export HISTCONTROL=ignorespace in .bashrc, bash won't record any commands which have whitespace before them into history. But I do not understand under what situations it will be useful. ...
19
votes
4answers
1k views

difference between function foo() {} and foo() {}

I can define bash functions using or omitting the function keyword. Is there any difference? #!/bin/bash function foo() { echo "foo" } bar() { echo "bar" } foo bar Both calls to functions ...
2
votes
3answers
198 views

Can I reload variable in a watch command?

Part of my job involves some data handling. One of the tasks is to 'flatten' a set of directories (which we'll call Dir for now), and copy them to a new location called DirFlat. This can take a long ...
2
votes
2answers
136 views

Sending binary data to gets()

I have a victim program (with a buffer overrun vulnerability): it uses gets() to write into a fixed-sized buffer. Suppose I put shellcode into a file SC. Then I run $ ./victim < SC Input your ...
2
votes
6answers
382 views

extract a file from jar file and get the diff

In real world I have a xsd in a jar file across various releases I am trying to check whether xsd has changed across releases 10.x.y.z to 11.a.b.c I have different release directories which are read ...
6
votes
2answers
234 views

Expand subshell before executing it?

I often run commands using subshells, and sometimes would like to have the subshells expanded before I run something.. This way I could verify what I'm doing, and possibly edit what's about to happen ...
2
votes
1answer
178 views

shell parameter substitution to rename files

I need to rename filenames which starts with "foo" into "boo" This is the script I used #!/bin/sh for f in *.jpg; do mv -- "{$f}" "${f/foo/boo}"; done but when i run I get a bad substitution ...
1
vote
1answer
58 views

Wrapper script to list sourced/executed files

Is it possible to write a command which runs my.sh and prints every path sourced or executed by this script recursively - That is, without altering the original code at all? The idea is to verify ...
1
vote
1answer
894 views

Multiple option arguments using getopts in bash

I am trying to process command line arguments using getopts in bash. One of the requirements is for the processing of an arbitrary number of option arguments (without the use of quotes). 1st example ...
1
vote
2answers
165 views

Direct recursive shell script output to each subdirectory, not parent directory

I'm processing a batch of subjects data recursively, calling the script within the parent directory. For example, I have the parent directory: /home/subjects and the subdirectories which contain ...
2
votes
2answers
76 views

“or” in shell glob

I want to ls the files containing the substring "s1r", "s2r", "s3r" or "s19r" in their filenames. I'm almost there! Botched attempts: ls *s[123][9?]r* The above gives me only files including the ...
2
votes
1answer
173 views

Invoking a script with ld-linux.so?

I just downloaded a tar file that is supposed to include everything required to run a program that we can call some_binary. I extracted it's contents, and I see the following: A binary (let's call ...
3
votes
2answers
889 views

How to print several files at the same time using lpr?

I am trying to print a number of files from shell using lpr. I enter something like: lpr -P PRINTERNAME ./*/dir/file.pdf but I get "lpr: No file in print request.". When I use ls as ls ...
4
votes
3answers
128 views

CD into directory from HISTORY in a bash script or alias e.g. $(!!)

I often want to change into the directory of a file on my file system, but I'm not sure where the file is. I search for it like so: find -type f -name "myfile.txt" Lets say for the sake of ...
2
votes
4answers
396 views

Problem understanding 'hash' command in a .sh file

So I wanted to install etherpad lite on a linux machine. If I try to run it, I will get the Error "Please install node.js ( http://nodejs.org )" the command 'which node' gives me the correct path to ...
4
votes
3answers
223 views

What process is running before I even get a prompt?

When I log in to a specific server I see the following: Note that I get get Last login: ... information but no prompt. I hit Ctrl+C and only then do I get my prompt, thus proving that my username ...
2
votes
2answers
845 views

Calling bash from sh (dash) with commands read from args, and “Unterminated quoted string”/“unexpected EOF”

Just thought I'd document this: I'm trying something very simple - set env variable in bash, and print it out: $ bash -c "a=1; echo a$a;" a $ bash -c "a=1; echo a\$a;" a1 Now I'd want this same ...
2
votes
1answer
37 views

Installing packages and tools on a local non-standard directory

TLDR: What environment variables should I update to guarantee that my system has access to everything a package provides when building it on a non-traditional path? I usually don't have root access ...
5
votes
1answer
1k views

How many users does Linux support being logged in at the same time via SSH?

I know Linux supports multiple users being logged in at the same time. But what's the maximum number of users that can be logged into Linux at the same time? I see there are there are 69 tty files ...
6
votes
2answers
537 views

Special character '#' in Perl SSH command

I try to send command using SSH in my perl script with # but it gets truncated right at # Example: Input text is : $message = "Product ID # STK000134" The SSH command is : $execute=`ssh -q ...
4
votes
4answers
813 views

Getting stdin from a named pipe

What I am trying to do is run python in a terminal window and redirect it's stdin from a named pipe. Then I write to the named pipe in another terminal and have that command execute on python. ...
2
votes
1answer
416 views

Run remote shell daemon as non root user with tab-completion

I need to run any "remote shell daemon" (ssh, telnet, netcat, socat... I don't mind) as non-root user. The remote shell should provide tab-completion and I want to be able to browse history using ...
5
votes
3answers
1k views

Count number of lines of output from previous program

I'm trying to count the number of lines of output a certain program produces. The problem is, the program takes a long time to run, and I want to display the output to the user. Is there a way to ...
0
votes
0answers
31 views

Pass process ownership to another shell [duplicate]

I didn't hear of anything like this, but It might be possible. I often end up starting a process on a server and midway realizing that I would like to suspend that process and continue it inside a ...
4
votes
3answers
243 views

Why should 'Character Classes' be preferred over 'Character Ranges' In Shell (Bash)?

The Linux Command Line (Book - page count 47) says: ... you have to be very careful with them [character ranges] because they will not produce the expected results unless properly configured. For ...
0
votes
1answer
1k views

How can I preserve new lines coming from a command's output during variable assignment?

Consider: $ getfacl somefile.dat # The output is formatted and contains several new lines.. # file: somefile.dat # owner: user1 # group: group1 user::rw- group::r-- #effective:r-- ...
1
vote
1answer
3k views

XML parsing using xmllint and customizing the output

I have xml file (say input.xml) of the following schema: <?xml version="1.0"?> <TagA> <TagB> <File Folder="FOLDER1M\1" File="R1.txt" /> </TagB> ...
0
votes
1answer
149 views

finger and who commands usage

I know that the finger command used to display information about local and remote users. finger --> display users log in on local machine, even if remotely. finger @hostname --> display users log in ...
0
votes
2answers
95 views

Supress expansion of * in echo

I am working on a script which dynamically executes some queries on daily basis. These queries are coming from a table in the database. Here is the sample output of the query table: ...
-1
votes
1answer
573 views

zsh: Is it worth the switch from bash? Is it the time? [closed]

I have been a bash user for years now. However, I find that zsh is increasingly gaining momentum. I came up with the following questions: Is zsh really becoming that popular? Will it compete with ...
0
votes
1answer
35 views

File inventories and logrotation

I want to collect a huge amount of data files on my actual netapp storage with the command file - f /path... > logfile.txt. Through the huge data amount, the size of the logfile will be critical. ...
0
votes
2answers
877 views

Cron job not running / not successful?

I have a couple of cron jobs set up to maintain a local copy of a remote database. The first one downloads the latest version of the database from the remote machine, which runs every day and is ...
3
votes
3answers
490 views

Can't process stdout with pipe as it comes

I'm running tshark on a fifo, and the following is a bare example of a loop that prints the output of tshark as it comes: tshark -i $fifo | while read line; do echo $line done The problem ...
3
votes
2answers
173 views

How to duplicate a stream and process both parts in a streaming way?

Sometimes I want to insert something in a pipeline for reporting or some other secondary use. It might be as simple as wc -l, or a more complex beast like awk or even a python script. It'd be nice to ...
1
vote
1answer
253 views

Safely convert unicode strings to printable characters

I have many HTML files containing mixed unicode strings like \303\243 and printable characters like %s. What I'd like to do is converting the unicode strings into printable characters in a safe way. ...
0
votes
2answers
114 views

Difference between eval and alias commands

what are the differences between eval and alias commands? Examples: x=‘ls -d -l $HOME’ $x eval $x alias y=‘ls -l -d $HOME’ y
2
votes
1answer
220 views

Execute commands coming from a serial port

I have some hardware that is sending commands over /dev/ttyACM0 every once in a while and I'd like to execute them in a terminal. For example, if the ascii "ls" comes over /dev/ttyACM0, I'd like to ...
1
vote
2answers
394 views

How to check in a shell script if an executable is running or not?

I have put an executable in a shell script file abc.sh. Now, I want to add one line in this abc.sh, to know whether it is running before my script starts or not and if yes, the kill that executable.
1
vote
8answers
134 views

remove content of directory in elegant way

I would like to remove all content of the current working directory. How to do it in efficient and elegant way? I have several files, directories and some of them starts with dot, like: touch .abc; ...
0
votes
2answers
38 views

can't update with this error messg

I got this message: not enough free disk space.... The upgrade needs a total of 31.8 M free space on disk '/boot'. Please free at least an additional 31.8 M of disk space on '/boot'. Empty ...
0
votes
3answers
2k views

Is there any website having command line environment of Linux, for practicing commands? [duplicate]

I was wondering whether I could practice Linux commands and shell scripting, online, over a website which could provide me an editor to practice them. And I know that probably the easiest thing to do ...
1
vote
1answer
514 views

How to create a password protected shell script [duplicate]

How can I create a password-protected shell script for read/write access. It should also be executable by all users without the password. I have sensitive information in the script.
0
votes
2answers
209 views

read file record by record and do transformation to the subsequent record based on above record and write into another file

Data file is fixed length file, and I want to read the file record by record and do transformations to the subsequent records based on the prior records (and write the results into another file). ...
1
vote
3answers
467 views

Why is this Bash command using regex not replacing my brackets?

I have this command to go through all my files in my Music directory, and all subdirectories, and replace any square brackets in the file name with rounded brackets: find /home/Music/ -depth -name "* ...
1
vote
1answer
272 views

stop processing in shell script but don't exit

I've got a script that I run continually to monitor vsftpd logs. Here is a small example: #!/bin/sh tail -n0 -F /var/log/vsftpd.log | while read line; do if echo "$line" | grep -q 'OK UPLOAD:'; ...
2
votes
1answer
159 views

Creating a terminal application from a shell script

I have a shell script. I want to convert the shell script to an application for Ubuntu which can be installed using (sudo apt-get install) command and after installing, the application can run from ...
0
votes
1answer
88 views

md5 String and File different

Why do I become a different hash when I try: md5 <<< "Hello" md5 -s "Hello" Is it because of a possible line break in the first example?
3
votes
1answer
1k views

Installing ksh as the standard shell in Redhat: Foolhardy?

I'm not a system administrator, but my organization is considering replacing /bin/sh in Red Hat Enterprise Linux 6+ with a hard link to /bin/ksh. How foolhardy would this be? The background to this ...