Tag Info

Hot answers tagged

10

There is a very easy and handy way: Using script Start the command script Start your script If your script is finished, stop script via Ctrl-D Check the output in the default output file typescript To start your command in one step with script, use the parameter -c -c COMMAND Run the COMMAND rather than an interactive shell. This makes it ...


9

If unzip would have adhered to the pipes and filters architectural style characteristic of Unix, then one would expect to be able to do this by piping the output of wget into the input of unzip: wget -O - http://www.test.com/test.zip | (cd destination-folder && unzip -) Where the the dash after -O means standard output, the dash after unzip means ...


8

You need more than one step: Go into your destination folder cd destination Download the file wget www.test.com/test.zip Extract the file unzip test.zip To use only one command use a script: #!/bin/bash wget -P "/tmp" "$1" filename=$(awk -F'/' {print $NF}) unzip "$filename" -d "$2" rm "/tmp/$filename" Open an editor to create a new file ...


8

The shell metacharacter && expects a command afterwards, that would be run if the first command succeeds. Thats why you are getting the error message. For example you have sleep 1&& at the 10th line, now the shell will run sleep 1 and then if it succeeds (exit code 0) then (&&) will run the next command, which is not provided by ...


7

if you normally run your script with foo.sh, try running it (assuming it's a bash script) with bash -x foo.sh. If you want everything redirected to file, try bash -x foo.sh > file.log 2>&1 (note I'm redirecting stderr as well, remove the 2>&1 if you don't want this). If you also want to see what's going on, bash -x foo.sh 2>&1 | tee ...


6

From bash(1) history [n] With no options, display the command history list with line numbers. Lines listed with a * have been modified.


5

The problem was that grive command was outputting to the error stream, STDERR (File descriptor 2), which is normally used for passing error messages while the STDOUT (File descriptor 1) is used for showing actual (upon success) output of any program (strictly speaking). I have not used grive, but according to your words the developer might have used STDERR ...


5

Since your files appear to contain sorted data, you should be able to use the join command e.g. join -12 -21 -t: -o1.1,2.2 file1.txt file2.txt > output.txt Then cat output.txt a2:c1 a4:c2 a5:c3 See man join for details of the options. If the files are not pre-sorted, then you can sort them first using process substitution. Note however that the ...


5

Here's an awk approach: awk -F: '(NR==FNR){a[$2]=$1; next}($1 in a){print a[$1]":"$2};' file1 file2 > out Explanation awk -F: Run awk, setting the field separator to :. This will read each input line and split it on :. So, for the first line of file1, the 1st field ($1) is a1 and the second ($2) is b1. (NR==FNR){} : If NR is equal to FNR. NR is the ...


4

You can't do this using the shell's field splitting. Adjacent whitespace characters from IFS are parsed together, so you cannot use field splitting to distinguish between adjacent whitespace IFS characters. From the standard (Shell and Utilities, section 2.6.5): Each occurrence in the input of an IFS character that is not IFS white space, along with any ...


3

It seems you have & somewhere in your url, hence the shell is sending the process to background. To solve this, quote the url. For example, if you use : curl https://www.example.com/myscript/foo&bar the shell will treat the url as https://www.example.com/myscript/foo and & after that will cause the curl https://www.example.com/myscript/foo ...


3

Get rid of the first line in that file. It reads ~/.profile: ... and bash tries to execute this file, the name of which ends with a :. That file does not exist, so bash complains, note the double: in the error messsge.


3

As far as I know, it is not possible to search sub strings of all possible commands at a time. You do though have the option of searching for sub strings of previously typed commands by using Ctrl+R and then typing your sub string. You can press Ctrl+R again to cycle through the previously typed commands containing this sub string


3

The last command sleep 1&& expects to have something else. If you remove last &&, there will be no error.


2

Back-up important files (if you have any) after booting from a live-cd, then reinstall system. This is the only option that I know of.


2

What you search is that: exec 1> >(tee -a $LOGFILE) Every data that is send trough channel 1 (stdout) is redirected line by line to tee which appends -a it to a file AND prints it to the stdout. If you want to redirect both, stdout and stderr, use this after the first exec statement from above: exec 2>&1


2

Those two are not same. exec is a shell builtin which will execute the given command ssh localhost in this case with replacing the current shell with the command. While doing simple ssh localhost you are executing general ssh command, there are no bells and whistles associated. The effect will be apparent when you will logout of the ssh session : In ...


2

XML is ok, parse is via awk, E.G.: location curl http://w1.weather.gov/xml/current_obs/KRAP.xml | \ awk -F'[<|>]' '/<location>/ {print $3}' Output Rapid City, Rapid City Regional Airport, SD location and weather curl http://w1.weather.gov/xml/current_obs/KRAP.xml \ | awk -F'[<|>]' '/<location>|<weather>/ {print ...


2

Your original code didn't work because you have to capture the whole while loop in the ans variable. Try the following snippet: #!/bin/bash INPUT=data.csv OLDIFS=$IFS IFS=";" ans=$(while read IP hostname subnetmask gateway do echo -e "$IP" done <$INPUT|zenity --list --text "Choose witch IP-address you want to connect to " --column "Choose") echo "You ...


2

Correct the following issues and check your script again here or see my corrections below 1 #!/bin/bash 2 3 source conf.ini 4 5 inotifywait -m -e create /$1path | 6 while read file; do 7 8 if ($(echo $word | head -c 1)"=$1 then ^––SC1009 The mentioned parser error was in this simple command. ...


2

In don't know what you are trying to do with this script but looking at it first time i see the errors are because of this line : if ($(echo $word | head -c 1)"=$1 then Make it as : if [ "$(echo $word | head -c 1)" = "$1" ]; then while doing a check with if-then conditional construct use test ([) or [[ (bash-ism). Check help test for more info. When ...


2

Replace log by an absolute path /home/katph/log E.G. #!/bin/bash echo "hi" > /home/katph/log exit 0


2

zsh might be able to get you halfway there: For me, zsh seems to prefer prefix completions (file<tab> will get me file filefrag file-roller, -file<tab> will get me apt-file desktop-file-install ecryptfs-rewrite-file grub-file ...). I don't understand the completion system well enough to make zsh do substring matching even if prefix matching ...


2

Well, this is being done your shell itself. Apparently it is monitoring the file (or directory) pointed by the MAIL (or MAILPATH) environment variable. This is documented in man bash : MAIL If this parameter is set to a file or directory name and the MAILPATH variable is not set, bash informs the user of the arrival of mail in the ...


2

Edit: I duplicated the missing # on the first part of the first line, and I get exactly the same error. There are great answers here to add the # back to the beginning of the first line which will get rid of that error message. In the meantime, if you want to create a new one, and I use these here scripts at work all the time to create new files, just ...


2

How about defining a custom bash function to do the job : move () { mv -- "$1" "$2"; cd -- "$_"; } put this move function at the end of your ~/.bashrc file. Run the function as move somefile somepath $1 is the first argument to the function (somefile) $2 is the second argument (somepath) $_ expands to the last argument of the previous command ($2 in ...


2

I feel both sorry and kind of embarrassed to tell you that the issue went away... The whole reason for that nothing happened if started from the .desktop launcher was a typo in the script path, so that the Exec=... line pointed to a non-existent file. I can only apologize to those who spent any of their time into this issue.


2

I think you will need to use while read line instead: x=0 while read line ; do x=$(($x+1)) done


2

You can do this using read in a while loop instead of a for loop: #!/bin/bash while read line; do ((x++)) done < file echo $x exit 0 ~$ cat file word word ~$ bash script.sh 5


1

Install the dconf-editor sudo apt-get install dconf-editor Start the application and navigate to org.gnome.terminal.legacy Open the category profiles: and select the wrong profile, or check all profiles. In the right hand pane you will see a key custom-command. Remove the value or use the Button Set to Default in the lower pane.



Only top voted, non community-wiki answers of a minimum length are eligible