简体   繁体   中英

Alias executes code instead of creating alias

In my ~/.bashrc file I defined the following alias: alias bwapp=service apache2 start;service mysql start;firefox http://localhost/bWAPP/bWAPP/portal.php

Then I restarted my computer and lauched terminal with the expectation of being able to run bwapp and lauch the portal, instead I was greeted with:

bash: alias: apache2: not found
bash: alias: start: not found
bash: service: command not found
Reading profile /etc/firejail/firefox.profile
Reading profile /etc/firejail/firefox-common.profile
Reading profile /etc/firejail/disable-common.inc
Reading profile /etc/firejail/disable-devel.inc
Reading profile /etc/firejail/disable-interpreters.inc
Reading profile /etc/firejail/disable-programs.inc
Reading profile /etc/firejail/whitelist-common.inc
Reading profile /etc/firejail/whitelist-var-common.inc
Parent pid 2913, child pid 2914
Warning: skipping pango for private /etc
Warning: skipping asound.conf for private /etc
Warning: skipping pki for private /etc
Warning: skipping crypto-policies for private /etc
Warning fcopy: skipping /etc/alternatives/fakeroot.sv.1.gz, cannot find inode
Warning fcopy: skipping /etc/alternatives/faked.sv.1.gz, cannot find inode
Private /etc installed in 95.44 ms
Post-exec seccomp protector enabled
Seccomp list in: @clock,@cpu-emulation,@debug,@module,@obsolete,@raw-io,@reboot,@resources,@swap,acct,add_key,bpf,fanotify_init,io_cancel,io_destroy,io_getevents,io_setup,io_submit,ioprio_set,kcmp,keyctl,mount,name_to_handle_at,nfsservctl,ni_syscall,open_by_handle_at,personality,pivot_root,process_vm_readv,ptrace,remap_file_pages,request_key,setdomainname,sethostname,syslog,umount,umount2,userfaultfd,vhangup,vmsplice, check list: @default-keep, prelist: adjtimex,clock_adjtime,clock_settime,settimeofday,modify_ldt,lookup_dcookie,perf_event_open,process_vm_writev,delete_module,finit_module,init_module,_sysctl,afs_syscall,create_module,get_kernel_syms,getpmsg,putpmsg,query_module,security,sysfs,tuxcall,uselib,ustat,vserver,ioperm,iopl,kexec_load,kexec_file_load,reboot,set_mempolicy,migrate_pages,move_pages,mbind,swapon,swapoff,acct,add_key,bpf,fanotify_init,io_cancel,io_destroy,io_getevents,io_setup,io_submit,ioprio_set,kcmp,keyctl,mount,name_to_handle_at,nfsservctl,open_by_handle_at,personality,pivot_root,process_vm_readv,ptrace,remap_file_pages,request_key,setdomainname,sethostname,syslog,umount2,userfaultfd,vhangup,vmsplice,
Child process initialized in 366.92 ms

Parent is shutting down, bye...

Aliases must be quoted if they contain spaces, semicolons, pipes, etc, eg:

alias ls='ls --color'

If you don't quote it ( alias ls=ls --color ), it will break on spaces, so alias will create an alias ls=ls , then try to look up an alias called --color , which doesn't exist, so you get bash: alias: --color: not found .

In your case the alias also contains unquoted semicolons, which end the current command, so service ... gives bash: service: command not found and firefox ... gives the rest of the output.

But ultimately this should be a function or script instead of an alias. See In Bash, when to alias, when to script, and when to write a function? on Unix & Linux. Personally I would go with a script:

#!/bin/bash

service apache2 start
service mysql start
firefox http://localhost/bWAPP/bWAPP/portal.php

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM