The shell is unix's command-line interface. You can type commands in a shell interactively, or write scripts to automate tasks.
2
votes
1answer
54 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
votes
0answers
50 views
shell scripts in linux [closed]
The "time and network" script
•Find the current time.
•If the current minute-of-the-hour is greater than 30, then use ifup to enable all network interfaces, otherwise disable all network interfaces ...
1
vote
1answer
17 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 ...
0
votes
1answer
87 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
45 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 ...
1
vote
2answers
45 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
41 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
61 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
70 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 ...
1
vote
4answers
82 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
123 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
59 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
25 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 ...
4
votes
1answer
277 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 ...
5
votes
2answers
192 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 ...
3
votes
4answers
80 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
96 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 ...
3
votes
3answers
93 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
29 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
77 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
49 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
92 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
57 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
71 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:
...
-4
votes
1answer
109 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
24 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
0answers
57 views
Samba guest access
I have a home server with samba. with windows i can access and make folder(always with permission 777) like guest( no password ) without problem. But with linux, when i mkdir i can not modify this ...
0
votes
2answers
57 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
91 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
33 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
65 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
39 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
1
vote
1answer
40 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
83 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
96 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
26 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
129 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
121 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
70 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
120 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
81 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:'; ...
1
vote
0answers
69 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
38 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
126 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 ...
1
vote
2answers
58 views
What do the bash-builtins 'set' and 'export' do?
I am at a bit of a loss as to the purpose of set and export in Bash (and I guess probably other shells too).
I would think it is for setting environment variables, but that can be done just with ...
8
votes
7answers
486 views
determine shell in script during runtime
As per my knowledge, to determine the current shell we use echo $0 in the shell. Rather I want my script to check in which shell it is running. So, I tried to print $0 in the script and it returns the ...
1
vote
2answers
42 views
How to strip directory structure with command line (or script)
I have a large collection of files packed into a two-level directory structure with many, many, many folders.
In other words, I have a folder with a great many subfolders in it. There are no ...
2
votes
1answer
56 views
Why is `kill -s INT <zsh PID>` behaving differently from `Ctrl-C`?
Starting with:
% donothing () { echo $$; sleep 1000000 }
% donothing
47139
If at this point I hit Ctrl-C at the same terminal that is controlling the shell, then the function donothing does indeed ...
3
votes
4answers
69 views
unzip file, which directory was created?
Objective:
After expanding archive a.zip by using command unzip on Ubuntu 12.10, assign the name of the folder a.zip expanded to to bash variable v.
a.zip is assumed and guaranteed to expand to a ...
0
votes
1answer
118 views
shell scripting escaping madness - sending single quotes to subshell
I'm beyond my skill level in getting this to work properly...
#!/bin/bash -x
# mxfbc.sh - mxf video file batch converter
# pass at the command line ...
# (1) the directory to batch convert (typically ...